Mocha Testing Framework
Qualified supports the Mocha testing framework, in a BDD or TDD setup.
The following is a Mocha BDD example on how to use the framework using the built in Node.js assertion library:
import {assert} from "chai";
import {add} from "./solution";
// import preloaded from "./preloaded"; // optionally, import the preloaded file
describe("add", () => {
before(() => { /* optional code to run before the entire suite */ });
beforeEach(() => { /* optional code to run before each test */ });
afterEach(() => { /* optional code to run after each test */ });
after(() => { /* optional code to run after the entire suite */ });
it("should add two numbers", () => {
assert.strictEqual(add(1, 2), 3);
});
});
Assertions
Mocha allows you to use any assertion library you want and so does not auto-require a certain library for you by default.
Chai
We recommend that you use the Chai BDD/TDD assertion library. It supports the following assertion styles:
Expect
const {expect} = require("chai");
expect(foo).to.be.a('string');
expect(foo).to.equal('bar');
expect(foo).to.have.length(3);
expect(tea).to.have.property('flavors').with.length(3);
Assert
const {assert} = require("chai");
assert.typeOf(foo, 'string');
assert.strictEqual(foo, 'bar');
assert.lengthOf(foo, 3)
assert.property(tea, 'flavors');
assert.lengthOf(tea.flavors, 3);