Full-Stack Web Development with Vue.js and Node

(singke) #1
Testing an MEVN Application Chapter 9

Let's also create a separate folder for test inside the test_js folder:


> mkdir test

To access mocha, you have to install it globally:


$ npm install mocha -g --save-dev

Let's write a simple test code in mocha. We will write a test for a simple function, which


takes two arguments and returns the sum of the arguments.


Let's create a file called add.spec.js inside the test folder and add the following code:


const addUtility = require('./../add.js');

Then, run the following command from the test_js folder:


$ mocha

This test will fail, and we will require a utility called add.js, which does not exist. It


displays the following error:

Free download pdf