无限茉莉花超时
Infinite jasmine timeout
这基本上是 Remove timeout for single jasmine spec github 问题的后续行动。
问题:
是否可以让单个测试永不超时?
问题:
可以通过 DEFAULT_TIMEOUT_INTERVAL
全局设置超时值,或者为每个描述 beforeEach
/afterEach
或在单个 it()
块上设置超时值:
it('Has a custom timeout', function() {
expect(true).toBeTruthy();
}, value in msec)
我对单个规范永不过时感兴趣。我已尝试遵循上述 github 问题中提出的建议并使用 Infinity
:
it('Has a custom timeout', function() {
expect(true).toBeTruthy();
}, Infinity)
但是,在测试进入 it()
块后,我立即收到以下错误:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL
我想我不能使用 Infinity
作为超时值,或者我做错了什么。
作为解决方法,我可以改用硬编码的大数字,但我想避免这种情况。
Jasmine 在内部使用 setTimeout
等待规范在定义的时间段内完成。
根据这个 Q/A - Why does setTimeout() "break" for large millisecond delay values?:
setTimeout using a 32 bit int to store the delay
...
Timeout values too big to fit into a signed 32-bit integer may cause
overflow in FF, Safari, and Chrome, resulting in the timeout being
scheduled immediately. It makes more sense simply not to schedule
these timeouts, since 24.8 days is beyond a reasonable expectation for
the browser to stay open.
一旦 Infinity
大于任何其他数字,就会发生溢出。
这种情况下的最大安全整数是 231-1 = 2147483647。这个值是有限的,所以测试实际上不会 运行 无限长,但如前所述,我认为 24.8 天已经足够了。
你可以定义一个常量来存储这个值:
jasmine.DEFAULT_TIMEOUT_INTERVAL = 2000;
var MAX_SAFE_TIMEOUT = Math.pow(2, 31) - 1;
describe('suite', function () {
it('should work infinitely long', function (done) {
setTimeout(function () {
expect(true).toBe(true);
done();
}, 3000)
}, MAX_SAFE_TIMEOUT);
});
这基本上是 Remove timeout for single jasmine spec github 问题的后续行动。
问题:
是否可以让单个测试永不超时?
问题:
可以通过 DEFAULT_TIMEOUT_INTERVAL
全局设置超时值,或者为每个描述 beforeEach
/afterEach
或在单个 it()
块上设置超时值:
it('Has a custom timeout', function() {
expect(true).toBeTruthy();
}, value in msec)
我对单个规范永不过时感兴趣。我已尝试遵循上述 github 问题中提出的建议并使用 Infinity
:
it('Has a custom timeout', function() {
expect(true).toBeTruthy();
}, Infinity)
但是,在测试进入 it()
块后,我立即收到以下错误:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL
我想我不能使用 Infinity
作为超时值,或者我做错了什么。
作为解决方法,我可以改用硬编码的大数字,但我想避免这种情况。
Jasmine 在内部使用 setTimeout
等待规范在定义的时间段内完成。
根据这个 Q/A - Why does setTimeout() "break" for large millisecond delay values?:
setTimeout using a 32 bit int to store the delay
...
Timeout values too big to fit into a signed 32-bit integer may cause overflow in FF, Safari, and Chrome, resulting in the timeout being scheduled immediately. It makes more sense simply not to schedule these timeouts, since 24.8 days is beyond a reasonable expectation for the browser to stay open.
一旦 Infinity
大于任何其他数字,就会发生溢出。
这种情况下的最大安全整数是 231-1 = 2147483647。这个值是有限的,所以测试实际上不会 运行 无限长,但如前所述,我认为 24.8 天已经足够了。
你可以定义一个常量来存储这个值:
jasmine.DEFAULT_TIMEOUT_INTERVAL = 2000;
var MAX_SAFE_TIMEOUT = Math.pow(2, 31) - 1;
describe('suite', function () {
it('should work infinitely long', function (done) {
setTimeout(function () {
expect(true).toBe(true);
done();
}, 3000)
}, MAX_SAFE_TIMEOUT);
});