Jasmine was created around 2008. 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.
Karma isn't a testing framework. So, it isn't a competitor to tools like Mocha, QUnit, or Jasmine, to name a few. Instead, Karma works with them, so you'll have to pick a testing framework to use. There are available plugins for the most well-known testing frameworks.
Mocha is significantly more flexible and comes with a test runner, but you have to piece it yourself. In the Angular world, Jasmine is the recommended testing framework. This is because Angular CLI, by default, comes with Jasmine and Karma as the test runner.
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.
Karma is a browser test runner.
The idea is that browsers do not have natively a concept of loading tests files, running them, and reporting results. What karma does is (roughly) :
Looking at each part :
(1) Those files will be your actual js files ; you will tell karma how to load them. If you use requirejs, there is a karma plugin, and some config is needed.
(2) Those tests can be written in a variety of Javascript testing framework (Jasmine, QUnit, Mocha) ; this is JS code that is run in the browser.
(3) The custom web page will be a bit different for each testing framework ; this is why karma has plugins for different frameworks.
(4) Karma can launch the page in many browsers (FF, Chrome, or headless browsers like PhantomJs.)
(5) Reporting to karma is, again, framework-dependant, and dealt with karma plugins.
So to answer your questions :
One shorter way to understand the difference:
People testing with plain Jasmine / Mocha most likely are running all the code with the Node virtual machine.
Adding Karma to the mix (on top of your existing framework of choice) will run your test suite with the engine of other browsers.
By doing this you get the little extras you get with a browser environment. It will be easier to test DOM related code, but you will also be giving up to the extra resources given by the Node engine (like filesystem / shell access)
The thesis of the guy who designed Karma was very informative in describing existing solutions and comparing them, and of course describing Karma itself
https://github.com/karma-runner/karma/blob/master/thesis.pdf
Summary: Karma is a test runner. It can be used by QUnit, Jasmine, Mocha, ... Karma has advantages to other test runners to improve your TDD/BDD development cycle. It "watches" files, so when you save a change, Karma runs tests and reports back instantly, no switching context to Web Browser to run the test.
In short, perhaps question should be Karma AND Jasmine or Mocha or QUnit?
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