mocha chai code example
Example 1: mocha timeout
describe("testing promises", function () {
this.timeout(5000);
});
Example 2: how to run mocha tests on asynchronous functions in script
it('responds with matching records', async function() {
const users = await db.find({ type: 'User' });
users.should.have.length(3);
});
it('should save without error', function(done) {
var user = new User('Luna');
user.save(function(err) {
if (err) done(err);
else done();
});
});
Example 3: chai js
Chai is an assertion library with 3 different assert styles,
namely "should", "expect" and "assert".
foo.should.equal('bar');
expect(foo).to.equal('bar');
assert.equal(foo, 'bar');
It can be used to replace the default assertion styles of JavaScript testing frameworks.