Testing with Mocha, Chai, Sinon, and npm

One of the great benefits of writing tests for your code is that you will be forced to think through how what you've written works. A test that is difficult to write might indicate code that is difficult to understand. On the other hand, comprehensive coverage with good tests helps others (and you) understand how an application works.

There are at least three notions to consider when setting up your test environment.

The purpose of testing is to make comparisons between the value of what is received and what is expected by your application code. As we saw earlier, Node's assert module is designed for this purpose, but its functionality is limited to individual, isolated assertions. We'll use the Chai library ...

Get Deploying Node.js 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.