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
This was a head scratcher at first, but you're using importing the wrong expect!
Change your import to:
And everything works. Here is the
expect
module. The module you're 'expect'ing to use is calledexpect.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!