Skip to content

Instantly share code, notes, and snippets.

Last active August 3, 2018 08:21
What would you like to do?
Setup mocha/chai.js/sinon stack w/ es6 features

Add the following development dependencies to your package.json (from the command line):

Using npm:

$ npm install cross-env mocha chai sinon sinon-chai chai-as-promised chai-datetime --save-dev

Using Yarn:

$ yarn add cross-env mocha chai sinon sinon-chai chai-as-promised chai-datetime --dev

Copy the mocha.conf.js file from this gist to your project's root directory.

Create the test/mocha.opts file specifying the following mocha options:

--require chai/register-expect
--require mocha.conf.js

If you're using babel in your project, you can also add the following option:

--require babel-core/register

Finally, add the test task to your package.json's script section:

  "scripts": {
    "test": "cross-env NODE_ENV=test mocha test/*.spec.js test/**/*.spec.js",

Done! You are ready to write your first test.

const chai = require('chai');
// globalize sinon
global.sinon = require('sinon');
// initialize chai plugins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment