我在摩卡使用瀏覽器運行亞軍一些異步測試,我試圖用柴的期待風格斷言:有沒有辦法讓Chai與異步摩卡測試一起工作?
window.expect = chai.expect;
describe('my test', function() {
it('should do something', function (done) {
setTimeout(function() {
expect(true).to.equal(false);
}, 100);
}
}
這不會給我正常的失敗斷言消息,而不是我得到:
Error: the string "Uncaught AssertionError: expected true to equal false" was thrown, throw an Error :)
at Runner.fail (http://localhost:8000/tests/integration/mocha/vendor/mocha.js:3475:11)
at Runner.uncaught (http://localhost:8000/tests/integration/mocha/vendor/mocha.js:3748:8)
at uncaught (http://localhost:8000/tests/integration/mocha/vendor/mocha.js:3778:10)
所以它顯然捕捉錯誤,它只是沒有正確顯示它。任何想法如何做到這一點?我想我可以用一個錯誤對象調用「完成」,但是然後我失去了Chai之類的所有優雅,並且它變得非常笨重......
問題是與瀏覽器端摩卡。有關此信息,請參閱https://github.com/visionmedia/mocha/pull/278。 –