Asserting tests with Chai.js

As you saw in the preceding unit test example, we used special blocks to define our test groups with Mocha, but we used a separate language when defining our actual individual tests. These tests are called assertions, and we chose to use the Chai.js library. This is purely a personal preference, as there are a number of different assertion libraries that exist. Each library does basically the same thing, with slight variations on the syntax and style of actually writing the tests. Since Chai.js is project specific and based on a personal preference, we will install it as a project dependency (instead of installing it globally). In addition, as our tests are not actually required for our application to run, we'll include Chai.js under the devDependencies list in our package.json file.

Performing npm install on the developer 's machine will yield all packages under normal dependencies, as well as devDependencies from package.json. When the environment changes to production, we will need to execute npm install --prod to specify the environment.

This will help npm to install packages under dependencies and not devDependencies from package.json. In order to include Chai.js in our project as a devDependency, we will use the --save-dev flag instead of --save when performing the npm install:

    $ npm install --save-dev chai
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.186.143