Zero configuration JavaScript Unit Testing with Mocha, Chai and Sinon
$ npm install --save-dev mokamokIn order to use the latest babel preset we need to install it:
$ npm install --save-dev babel-preset-latestCreate a directory called --tests--, and add a test file increment.spec.js:
import increment from '../increment';
describe("increment.js", () => {
it("should increment the value", () => {
expect(increment(7)).to.equal(8);
});
});Let's implement the increment.js module:
export default function (v) {
return v + 1;
}Modify the package.json file:
"scripts": {
"test": "mokamok"
},Run the test:
$ npm testMocks the file
Stop mocking the file
Usage: index [options]
Options:
-h, --help output usage information
-v, --version output the version number
-m, --automock mock every module in the project automatically
-j, --jsdom use jsdom
-w, --watch watch for file changes
-c, --coverage generate a code coverage report
-d, --test-directory <name> test directory name
-B, --no-babel disable babel support
Mokamok is based on Mocha and automatically injects Chai, Sinon and sinon-chai. Optionally it makes jsdom available.