可以't为jasmine设置超时

Can't set timeout for jasmine

本文关键字:jasmine 设置 超时 可以      更新时间:2023-09-26

我已经尝试了这个答案中的所有解决方案,但没有一个对我有效。

我正在使用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函数。

我怎样才能防止茉莉花这样不合时宜?

尝试在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位整数来存储延迟,因此超过此值的整数值将导致溢出。请参阅以下帖子:无限茉莉超时