Skip to content

Instantly share code, notes, and snippets.

@CarlOlson
Last active June 15, 2018 13:53
Show Gist options
  • Save CarlOlson/db1c0c113be0400a98067ba29a02ac2d to your computer and use it in GitHub Desktop.
Save CarlOlson/db1c0c113be0400a98067ba29a02ac2d to your computer and use it in GitHub Desktop.

Mocha + ES6

Setup

Run the following shell commands:

npm init
npm i --save-dev mocha chai babel-register babel-preset-es2015

Open up package.json and set your test script to the following: mocha --watch --compilers js:babel-core/register

Create a .babelrc file in the project directory:

{
  "presets": ["es2015"]
}

Example sources

// test/main.test.js
import { expect } from 'chai';

import Main from '../src/main';

describe('Main', () => {

    it('should be a class', () => {
        expect(new Main()).to.not.equal(undefined);
    });

});
// src/main.js
export default class Main {
    constructor() {
    }
}

Example output

> npm run test

  Main
    ✓ should be a class


  1 passing (12ms)
@cjoshmartin
Copy link

Thank you this was very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment