Can't set timeout for jasmine

对着背影说爱祢 提交于 2019-12-07 01:33:54

问题


I've tried all the solutions in this answer but none of them work for me.

I'm using jasmine v2.3.2 and jasmine-core v2.3.4

When I do this test:

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 see on my console that the request took only 3000 milliseconds. I even see my got here log.

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

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?


回答1:


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
    });
})

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



来源:https://stackoverflow.com/questions/34665214/cant-set-timeout-for-jasmine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!