I'm getting a strange error while using Mocha with Chai for the first time. The only framework I've used before is Jasmine, if that should help you figure out what I'm doing wrong.
I'm simply trying to make sure my constructor doesn't throw an error. I've been able to reduce the code to this, still getting the error:
class MyLib {
constructor() {}
}
export default MyLib;
This is the test file:
import chai from 'chai';
let { expect } = chai;
import MyLib from '../index';
describe('mylib-js', () => {
describe('constructor', () => {
it('should work', () => {
expect(new MyLib()).to.not.throw();
})
});
});
This is the output from Mocha:
d:\path\to\mylib-js>mocha --require babel-core/register
mylib-js
constructor
1) should work
0 passing (23ms)
1 failing
1) mylib-js constructor should work:
AssertionError: expected {} to be a function
at Assertion.an (d:\path\to\mylib-js\node_modules\chai\lib\chai\core\assertions.js:169:10)
at Assertion.assert (d:\path\to\mylib-js\node_modules\chai\lib\chai\utils\addChainableMethod.js:84:49)
at Assertion.assertThrows (d:\path\to\mylib-js\node_modules\chai\lib\chai\core\assertions.js:1273:32)
at Assertion.ctx.(anonymous function) [as throw] (d:\path\to\mylib-js\node_modules\chai\lib\chai\utils\addMethod.js:41:25)
at Context.<anonymous> (test.js:10:4)
at callFn (C:\Users\Myuser\AppData\Roaming\npm\node_modules\mocha\lib\runnable.js:315:21)
at Test.Runnable.run (C:\Users\Myuser\AppData\Roaming\npm\node_modules\mocha\lib\runnable.js:308:7)
at Runner.runTest (C:\Users\Myuser\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:422:10)
at C:\Users\Myuser\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:533:12
at next (C:\Users\Myuser\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:342:14)
at C:\Users\Myuser\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:352:7
at next (C:\Users\Myuser\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:284:14)
at Immediate._onImmediate (C:\Users\Myuser\AppData\Roaming\npm\node_modules\mocha\lib\runner.js:320:5)
I have no idea where it gets {}
from in the error output. What is it trying to tell me?