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.
Let's use chai
in our previous test. In add.spec.js
, add the following lines of code:
var expect = require('chai').expect; var addUtility = require("./../add.js"); describe('Add', function(){ describe('addUtility', function(){ it('should have a sum method', function(){ expect(addUtility).to.be.an('object'); expect(addUtility).to.have.property('sum'); }) it('addUtility.sum(5, 4) should return 9', function(){ expect(addUtility.sum(5, 4)).to.deep.equal(9); }) it('addUtility.sum(100, 6) should return 106', function(){ expect(addUtility...