問題描述
jasmine 2 遇到問題并連接異步規范:
Having trouble with jasmine 2 and getting async specs wired up:
define(['foo'], function(foo) {
return describe('foo', function() {
beforeEach(function(done) {
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
return setTimeout((function() {
console.log('inside timeout');
return done();
}), window.jasmine.DEFAULT_TIMEOUT_INTERVAL);
});
return it('passes', function() {
return expect({}).toBeDefined();
});
});
});
當我通過業力奔跑時,我會回來
When I run via karma, I get back
錯誤:超時 - 未在超時內調用異步回調由 jasmine.DEFAULT_TIMEOUT_INTERVAL 指定.
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
然后規范失敗.我試圖覆蓋默認超時,但我無法克服錯誤
and then the specs fail. I have attempted to override the default timeout but I can't get past the error
推薦答案
您正在使用與 Jasmine 相同的超時間隔來失敗測試超時,即您的超時被觸發以使用 Jasmine 的默認間隔觸發,這會導致測試失敗.
You are using the same timeout interval as Jasmine is using to fail tests on timeout, i.e. your timeout is triggered to fire with Jasmine's default interval, which fails the test.
如果您將超時設置為小于 jasmine 默認超時,則測試通過.
If you set your timeout to be less than jasmine default timeout the test passes.
describe('foo', function () {
beforeEach(function (done) {
window.jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
setTimeout(function () {
console.log('inside timeout');
done();
}, 500);
});
it('passes', function () {
expect({}).toBeDefined();
});
});
見小提琴這里
這篇關于jasmine 2 - 在 jasmine.DEFAULT_TIMEOUT_INTERVAL 指定的超時時間內未調用異步回調的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!