0
我不能在這個簡單的例子柴expect
工作:摩卡的done
功能似乎永遠不會被調用,並聲明會被忽略:摩卡和柴失敗insde一個承諾
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();
});
});
});
注意,我已經用盡全力,有和沒有chai-as-promised
的eventually
。
這是相關的輸出:
> 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.
正如你所看到的,許是工作,我得到我的控制檯輸出。但是expect()
調用都不起作用,done()
調用也不做任何事情。
我不確定它是否相關,但我使用isomorphic-fetch
和建議的es6-promise
。
用'this.timeout(50000)嘗試''後,它()' – slorenzo