Contact us now for a free tech consultation +5492235066274 hello@xoor.io

Introduction

Welcome again! If you reached this post from nowhere and don’t understand what all this is about, you can check out the previous posts:

You can find the code for this tutorial in GitHub. If you followed the steps from the previous posts your project directory structure should look like this:

├── config
│   ├── env
│   │   ├── development.js
│   │   └── index.js
│   ├── express.js
│   └── jwt.js
├── gulpfile.babel.js
├── index.js
├── package.json
└── server
    ├── controllers
    │   ├── auth.js
    │   ├── tasks.js
    │   └── users.js
    ├── models
    │   ├── task.js
    │   └── user.js
    └── routes
        ├── auth.js
        ├── index.js
        ├── tasks.js
        ├── users.js
        └── validation
            └── tasks.js

If it doesn’t, please go back and check if you missed something from the previous posts.

Unit Testing

This is the last post of the series, and we’ll add some unit tests to the API we’ve built. It’s always important to have unit tests, because if in the future we do any kind of changes to the API code, we can quickly check if all the responses are still as expected or not. We can also check with unit tests what will happen when errors occur and see if the error responses are correct as well. For the unit tests implementation we’ll install a widely used test runner for Node.js called Mocha and some other dependencies we’ll install as they are needed during the post. So let’s just install mochafor now: npm install --save-dev mocha@^2.3.4