【问题标题】:Can't set timeout for jasmine无法为茉莉花设置超时
【发布时间】:2016-01-07 21:09:46
【问题描述】:

我已经尝试了this answer 中的所有解决方案,但没有一个对我有用。

我正在使用jasmine v2.3.2jasmine-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);

我在控制台上看到该请求只用了 3000 毫秒。我什至看到了我的got here 日志。

显示超时的日志打印出30000,而不是像我预期的那样打印出999999

我也收到此测试失败的消息:

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 函数。

我怎样才能防止茉莉花像这样超时?

【问题讨论】:

  • jasmine.DEFAULT_TIMEOUT_INTERVAL 应该在顶级代码上。您是否尝试将其放在任何 describe 之外?
  • @just-boris 是的。我已经更新了我的代码以显示这一点

标签: javascript node.js jasmine


【解决方案1】:

尝试在beforeAll 中设置jasmine.DEFAULT_TIMEOUT_INTERVAL,因为每个it 块的超时间隔都会重置:

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 位整数来存储幕后的延迟,因此超过此值的整数值将导致溢出。看到这个帖子: Infinite jasmine timeout

【讨论】:

  • Jasmine 当前 (2.5.38) 的行为与您描述的不同。 beforeAll 块中设置的自定义超时存在于每个 it 块中。
  • ARH。我读了一个指南,说第三个参数是重试次数。原来,jasmine this.it = function(description, fn, timeout) {实际上是超时了
猜你喜欢
  • 2015-11-26
  • 1970-01-01
  • 2014-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-26
相关资源
最近更新 更多