Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocha ES6 tests supported?

I'm attempting to use expect tests with mocha, written in ES6, and am getting TypeError even with a simple test case:

import expect from "expect"; 

describe('Example', () => {
  it('should just work', (done) => {
    expect(5).to.eql(5);
    done();
  });
});

I'm using Babel to convert and run the tests:

./node_modules/.bin/mocha --compilers js:babel/register example.js

Which results in:

  Example
    1) should just work


  0 passing (76ms)
  1 failing

  1) Example should just work:
     TypeError: Cannot read property 'eql' of undefined
      at Context.<anonymous> (example.js:5:17)

Is this not supported, or am I missing something critical?

Versions:

  • babel 5.5.6
  • expect 1.6.0
  • mocha 2.2.5
like image 376
Collin Allen Avatar asked Jun 23 '15 22:06

Collin Allen


1 Answers

This was a head scratcher at first, but you're using importing the wrong expect!

Change your import to:

import expect from "expect.js"; 

And everything works. Here is the expect module. The module you're 'expect'ing to use is called expect.js

Hope this helps, and sorry for the bad pun :)

Edit: You'll also have to be sure to npm install expect.js as well!

like image 79
Brennan Avatar answered Oct 19 '22 17:10

Brennan