by mjackson · 11y ago · 0 comments
Karma is a test runner. Use Karma to launch and run your tests in real browser instances. There is no better tool available for doing this.
Mocha is used to actually create your test suite. It's great at describing how your tests should run, with stuff like before/afterEach, it.only, describe.skip, etc. Use Mocha to describe which tests you want to run and how they should run.
You can easily load Mocha onto the page in your karma config using the karma-mocha plugin. Then, one line in your karma config and you're done. https://github.com/rackt/react-router/blob/53623216560e34fbe...
As for file watching (also part of the OP) your bundler should be doing that. Use karma-webpack (or whatever tool you're using to create your bundle).
Finally- probably the best thing about Karma is its wide support in the community. You can find a Karma plugin for just about any other tool you might want to use, including launchers for hosted browser environments like Sauce Labs and BrowserStack.
Also, from first glance, I'm unable to see a performance improvement by not using Karma. It may be because they're using more tests in Mocha, but the difference isn't huge considering they're losing a lot of functionality.
We use test-automation for real browser testing but prefer to rely on quick and functional unit-testing, thus the choice to go with jsdom.
Regarding the community, you're right, there's a `karma-something` for every need. However, mocha is pretty popular too, and getting momentum by the day. Also the fact that it simply runs on Node makes it quite easy to obtain what you want without extra plugins (e.g. coverage).
Click bait adds no value to the discussion.
There's no either/or when it comes to karma/mocha. As the commenters above mentioned, it's best to use both. Mocha for quick unit testing, karma for in-browser testing.
In-browser testing can be automated to run on a wide range of browsers and platforms using integration tools such as Browser Stack.
By faking the DOM, you remove nerf the greatest advantage of client-side integration testing. Checking functionality under realistic circumstances.