Mocha, Chai and Sinon Install mocha and chai: Install mocha and chai: update the scripts section of package.json update the scripts section of package.json ...run with npm test ...run with npm test A mocha Test A mocha Test ...with chai ...with chai chai cheatsheet chai cheatsheet Chai provides a DSL that supports chaining of three types of Particles CHAINS: add expressivity, do not modify the behavior of assertions to, be, been, is, which, has, have, at... Flags: modify the behavior of assertions not, deep... Assertions: perform the actual check equal, true, false, empty, undefined, exist, a... below, within, closeTo, most, throw Example: expect(1).to.be.ok expect(true).to.be.true expect(1).to.not.be.true expect(null).to.not.exist expect(undefined).to.not.exist expect(something).to.not.be.equal(other) expect(1).to.be.below(2) expect(1).to.be.at.most(2) expect(2).to.be.above(1) expect(1).to.be.at.least(1) expect(2).to.be.within(1, 3) expect(2.2).to.be.closeTo(2, 0.2) expect([1, 2, 3]).to.have.length(3) expect([1, 2]).to.have.length.of.at.most(3) expect([1, 2]).to.have.length.of.at.least(1) expect({ name : 'Joe' }).to.include.keys('name') var cantSayHello = function () { throw new Error() } expect(cantSayHello).to.throw(Error) Chai provides a DSL that supports chaining of three types of Particles CHAINS: add expressivity, do not modify the behavior of assertions to, be, been, is, which, has, have, at... Flags: modify the behavior of assertions not, deep... Assertions: perform the actual check equal, true, false, empty, undefined, exist, a... below, within, closeTo, most, throw Example: expect(1).to.be.ok expect(true).to.be.true expect(1).to.not.be.true expect(null).to.not.exist expect(undefined).to.not.exist expect(something).to.not.be.equal(other) expect(1).to.be.below(2) expect(1).to.be.at.most(2) expect(2).to.be.above(1) expect(1).to.be.at.least(1) expect(2).to.be.within(1, 3) expect(2.2).to.be.closeTo(2, 0.2) expect([1, 2, 3]).to.have.length(3) expect([1, 2]).to.have.length.of.at.most(3) expect([1, 2]).to.have.length.of.at.least(1) expect({ name : 'Joe' }).to.include.keys('name') var cantSayHello = function () { throw new Error() } expect(cantSayHello).to.throw(Error) npm install mocha chai –save-dev npm install mocha chai –save-dev ADDING A CONTEXT ADDING A CONTEXT beforeEach: to create the Test Fixture before each Test Case is run (the same Employee in our example ) beforeEach: to create the Test Fixture before each Test Case is run (the same Employee in our example ) context: to wrap together several Test Cases that share the same set up context: to wrap together several Test Cases that share the same set up describe: wrap together several Test Cases, creating a Test Suite for a common feature or behavior describe: wrap together several Test Cases, creating a Test Suite for a common feature or behavior