jasmine 2 - 在 jasmine.DEFAULT_TIMEOUT_INTERVAL 指定的超时时间内未调用异步回调
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();
});
});
见小提琴这里
相关文章