I can't make Chai expect
work in this simple example: Mocha's done
function never seems to get called and assertions are simply ignored:
import chai, {expect} from 'chai';
import chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised);
import 'isomorphic-fetch';
describe('Mocha and Chai', () => {
it('tests chai expect inside a promise', (done) => {
fetch('http://google.com').then(() => {
const actual = 'test';
const expected = 'expected';
console.log(`'${actual}'' equals to '${expected}'?`, actual === expected);
expect(actual).to.be.equals(expected);
expect(actual).to.eventually.be.equals(expected);
done();
});
});
});
Note that I have tried both, with and without chai-as-promised
's eventually
.
This is the relevant output:
> mocha tools/testSetup.js "src/**/*.spec.js" --reporter progress
'test'' equals to 'expected'? false
1) Mocha and Chai tests chai expect inside a promise:
Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
As you can see, the promise is working, I get my console output. But neither the expect()
calls work nor the done()
call does anything.
I am not sure if it's relevant, but I'm using isomorphic-fetch
and the suggested es6-promise
.