Test runners are the most fundamental part of the testing stack. If you have a clunky or cumbersome way to run your tests, you will abandon testing long before you can experience the advantages or disadvantages of frameworks and assertion libraries. In my own testing journey, discovering and incorporating Karma into the testing stack was a game-changer. Karma runs your suite of tests in one or more browsers of your choice automatically. It is particularly useful to ensure that your code is safe from browser implementation quirks, and provides a level of confidence unmatched by other solutions. Karma can be configured to run against browsers locally or to use remote services like Sauce Labs and BrowserStack.
Karma is my runner of choice, but many React developers turn to the Mocha CLI for simplicity. We’ll discuss Mocha in the section on test frameworks, but for now I’ll just mention that the Mocha CLI will easily run your Mocha tests in a Node.js environment. The ease of this basic approach poses a bit of a problem if you want to test component interactions that rely on rendering or the DOM, in which case you’ll have to incorporate something like Enzyme or JSDOM, respectively. Unfortunately, there isn’t a mechanism to run tests in the browser using the Mocha CLI. That limitation can simplify the decision-making process if you’ve got hard requirements for in-browser testing. The two other test frameworks we’ll review, Jasmine and Jest, also have CLIs to help run their tests. These two CLI tools have the same benefits and drawbacks as the Mocha CLI.