Mocha and Chai are usually used for JavaScript unit tests. Mocha and Chai run on Node. js as well as in the browser. Mocha is a test framework and Chai is a BDD / TDD assertion library. We will be using them to design our automated test scripts:
- First, let's install Mocha and Chai with the help of the following command:
[root@ip-172-31-95-213 node-api]# npm install --global mocha
[root@ip-172-31-95-213 node-api]# npm install --save-dev mocha
[root@ip-172-31-95-213 node-api]# npm install --save-dev chai
[root@ip-172-31-95-213 node-api]# npm install --save-dev chai-http
- Next, we will install the request package to send our test HTTP requests as shown here:
[root@ip-172-31-95-213 node-api]# npm install request --save-dev
- We have to include the Mocha test command in the scripts object inside the package.json file:
[root@ip-172-31-95-213 node-api]# vi package.json
------------------------------------------
{
"name": "node...