Skip to content

Instantly share code, notes, and snippets.

@BCEvanFang
Created November 29, 2018 02:19
Show Gist options
  • Select an option

  • Save BCEvanFang/35a9e8e46990b10e56b38866dcfd1774 to your computer and use it in GitHub Desktop.

Select an option

Save BCEvanFang/35a9e8e46990b10e56b38866dcfd1774 to your computer and use it in GitHub Desktop.
A simple mocha unit test example
// install test tools
// npm install mocha chai --save
/*
add.js
*/
function add(x, y) {
return x + y;
}
module.exports = add;
/*
add.test.js
*/
var add = require("./add.js")
var expect = require("chai").expect;
describe('Add function', () => {
it('1 + 2 = 3', () => {
expect(add(1, 2)).to.be.equal(3);
});
});
// test command
// mocha ./add.test.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment