36

I am new to the Javascript world, being majorly into OOP. I have tried to look up online for a clear cut distinction between Karma and Mocha but in vain. I know Karma is a Test Runner and Mocha is a unit testing Framework, but Mocha also has its own driver and can be used for running tests in the browser. That said, I don't understand what Karma brings to the plate, and why are people using these in conjunction.

Setafire
  • 719
  • 2
  • 9
  • 21

1 Answers1

30

Imagine the following scenario:

  • Write your own test suites with Mocha

  • Use Karma to run programmatically your Mocha tests cross-browser and cross-devices

  • More, integrate Karma with your Jasmine existing environment

  • Even more, integrate Karma in your Continuous Integration cycle

  • Use a million Karma plugin to check coverage, complexity, framework stuff, etc...

The power of Karma is that it can spawn real browsers - such Chrome or Firefox - to effectively test your code with them.

With Mocha you can run it in a NodeJS environment or in a webpage.

Rakibul Haq
  • 1,348
  • 23
  • 32
MarcoL
  • 9,829
  • 3
  • 37
  • 50
  • 1
    To be fair though, you can run mocha in multiple browsers to get the cross-browser effect you list. Karma really shines as a test runner, continuous integration, retesting on file change, ability to use in conjunction with jasmine/qunit, etc – Harry Moreno Sep 16 '15 at 06:26
  • That is what I am saying, nothing different than you. ;) – MarcoL Sep 16 '15 at 06:31