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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With