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:
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With