Prepare for Client-Side Testing

To automatically verify the behavior of the client-side code, we have to follow a few steps: load the code and the tests into different browsers, execute the tests, assert expectations, and generate a report of the run. The three tools we already looked at, Mocha, Chai, and Istanbul, can help with test execution, assertion, and coverage report. To automatically load code and tests into browser—that’s where Karma comes in.

Karma is a lightweight server that manages the loading and running of tests in different browsers. You can tell Karma what browsers you’d like to use and also what testing tools to employ, and Karma takes care of the rest.

Karma can run in auto watch mode, which means that anytime any ...

Get Test-Driving JavaScript Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.