Mocha ES6 tests supported?

I try to use expect mocha tests written in ES6, and I get a 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 use Babel to convert and run tests:

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

Result:

  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
+7
javascript ecmascript-6 mocha
source share
1 answer

At first it was the main scraper, but you are using the import of the wrong wait!

Change your import to:

 import expect from "expect.js"; 

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

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

Edit: You must also be sure of npm install expect.js !

+8
source share

All Articles