Mocha & Chai
Install and usage
test command (also as answer to npm init)
mocha --reporter spec
npm -i mocha -D
npm -i chai -D
Sample test - in "test" dir
'use strict';
var expect = require('chai').expect; // chai is an assertion library
describe('A Test Template', function () {
var somethingToPassBetweenHooksAndTests = 'something'
// hooks
before(function () {
// runs before all tests in this block
this.alsoSomthingToPassBetweenHooksAndTests = 'yet something'
});
after(function () {
// runs after all tests in this block
});
beforeEach(function () {
// runs before each test in this block
});
afterEach(function () {
// runs after each test in this block
});
// test cases
// using arrow function is discouraged
// a synchronous test case
it('should works this way...', function () {
// do something with your module
expect(somethingToPassBetweenHooksAndTests).to.equal('something');
expect(this.alsoSomthingToPassBetweenHooksAndTests).to.equal('yet something');
});
// an asynchronous test case
it('responds with matching records', async function () {
// const users = await db.find({
// type: 'User'
// });
// users.should.have.length(3);
});
});