无法为茉莉花设置超时 [英] Can't set timeout for jasmine
问题描述
我已经在这个答案,但它们都不适合我。
I've tried all the solutions in this answer but none of them work for me.
我正在使用 jasmine v2.3.2
和 jasmine-core v2.3.4
当我做这个测试时:
jasmine.DEFAULT_TIMEOUT_INTERVAL= 999999;
describe('tests content controller', function(){
//...
fit('/content should return 200',function(done){
request(app)
.get('/content?type=script')
.set('Authorization', "bearer " + requestor.token)
.set('Accept', 'application/json')
.expect(200)
.end(function (err, res) {
if (err) done.fail(err);
expect(res.statusCode).toBe(200);
console.log('got here');
console.log(jasmine.DEFAULT_TIMEOUT_INTERVAL); //prints 30000
done();
})
},999999);
I在我的控制台上看到请求只花了3000毫秒。我甚至看到我的到了这里
log。
I see on my console that the request took only 3000 milliseconds. I even see my got here
log.
日志显示超时打印出 30000
而不是 999999
就像我期望的那样。
The log that shows the timeout prints out 30000
and not 999999
like I expect.
我的测试也失败了消息:
I also get a failure for this test with the message:
Message:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
Stack:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
1 spec, 1 failure
Finished in 33.069 seconds
有一些初始设置导致大部分~30秒延迟。应用程序必须连接到多个数据库并在 describe
中运行 beforeAll
函数。
There is some initial setup which causes the majority of this ~30 second delay. The application has to connect to several databases and run the beforeAll
function in the describe
.
我怎样才能防止茉莉花这样超时?
How can I get prevent jasmine from timing out like this?
推荐答案
尝试设置 jasmine.DEFAULT_TIMEOUT_INTERVAL
在 beforeAll
中,因为每个重置超时间隔
block:
Try setting the jasmine.DEFAULT_TIMEOUT_INTERVAL
in a beforeAll
, since the timeout interval is reset for each it
block:
describe("testing timeout", function() {
beforeAll(function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 999999;
});
fit('should have custom timeout', function(){
console.log(jasmine.DEFAULT_TIMEOUT_INTERVAL); //prints 999999
});
})
此外,请保持请记住,setTimeout使用32位整数来存储幕后延迟,因此超过此值的整数值将导致溢出。看这篇文章:
无限茉莉花超时
Also, keep in mind that setTimeout is using a 32 bit integer to store the delay behind the scenes, so integer values that exceed this will cause overflow. See this post: Infinite jasmine timeout
这篇关于无法为茉莉花设置超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!