Book Image

Deploying Node.js

By : Sandro Pasquali
Book Image

Deploying Node.js

By: Sandro Pasquali

Overview of this book

If you are an intermediate or advanced developer deploying your Node.js applications, then this book is for you. If you have already built a Node application or module and want to take your knowledge to the next level, this book will help you find your way.
Table of Contents (9 chapters)
8
Index

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 (http://chaijs.com), which provides you with a richer choice of languages and idioms to make assertions with.

It is not unusual for an application to be covered by several hundred tests. When assertions are grouped, say by feature or business unit...