Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Karma and Mocha

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.

like image 861
Setafire Avatar asked Apr 24 '14 14:04

Setafire


People also ask

What is difference between karma and Jasmine?

Jasmine can be classified as a tool in the "Javascript Testing Framework" category, while Karma is grouped under "Browser Testing". "Can also be used for tdd " is the primary reason why developers consider Jasmine over the competitors, whereas "Test Runner" was stated as the key factor in picking Karma.

What is difference between mocha and chai?

Mocha is a JavaScript test framework running on Node. js and in the browser. Mocha allows asynchronous testing, test coverage reports, and use of any assertion library. Chai is a BDD / TDD assertion library for NodeJS and the browser that can be delightfully paired with any javascript testing framework.

What is the difference between mocha and Jasmine?

The documentation describes Jasmine as “batteries included,” meaning that it attempts to provide everything a developer needs in a test framework. Mocha is younger than Jasmine, created around 2011. Mocha is not a “complete” test framework, and doesn't attempt to be.


1 Answers

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.

like image 77
MarcoL Avatar answered Sep 19 '22 09:09

MarcoL