admin管理员组

文章数量:1345448

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?

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?

Share Improve this question edited May 23, 2017 at 12:09 CommunityBot 11 silver badge asked Jan 7, 2016 at 21:09 user773737user773737 2
  • 2 jasmine.DEFAULT_TIMEOUT_INTERVAL should be on the top level code. Have you tried to put it outside of any describe? – just-boris Commented Jan 7, 2016 at 21:15
  • @just-boris yes. I've updated my code to show that – user773737 Commented Jan 7, 2016 at 21:22
Add a ment  | 

1 Answer 1

Reset to default 11

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

本文标签: javascriptCan39t set timeout for jasmineStack Overflow