Full-Stack Web Development with Vue.js and Node

(singke) #1
Testing an MEVN Application Chapter 9

})
})
});

Then, take a look at the test; it fails. Then, add the logic to our module:


var addUtility = {}

addUtility.sum = function (a, b) {
'use strict';
return a + b;
}

module.exports = addUtility;

Then, rerun mocha and the test should pass. That's it!:


You can go on adding a few more cases to the test to ensure that nothing breaks.


Introducing chai


Let's discuss chai. chai is an assertion library, used with mocha. We could also use the


native assertion library , but chai adds a lot of flexibility.


chai makes it a lot easier to write test definitions. Let's install chai and modify the


preceding test to make it look more simple and easy to understand:


$ npm install chai -g

We passed the -g option to install it globally, since we do not have a package.json


configuration.

Free download pdf