Book Image

Node.js By Example

Book Image

Node.js By Example

Overview of this book

Table of Contents (18 chapters)
Node.js By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preparing our project to run tests


Now we know what tools we need to run our tests. The next step is to prepare our project to place such tests. Normally during development, we test our application by visiting the pages and interacting with them. We know the result of these actions and we verify if everything is okay. We want to do the same thing with automated tests. However, instead of us repeating the same steps again and again, there will be a script.

In order to make these scripts work, we have to put them in the right context. In other words, they should be executed in the context of our application.

In the previous section, we mentioned Chai (an assertion library) and Mocha (a testing framework). They play well together. So, we will add them to our list of dependencies, as follows:

// package.json
…
"dependencies": {
    "chai": "2.0.0",
    "mocha": "2.1.0",
    ...
}
…

A quick run of npm install will set up the modules in the node_modules directory. Chai and Mocha are distributed as...