9

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?

Community
  • 1
  • 1

1 Answers1

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

Community
  • 1
  • 1
Adam T. Smith
  • 376
  • 3
  • 8
  • 2
    Jasmine's current (2.5.38) behavior is not as you described it. A custom timeout set in a `beforeAll` block is present in each `it` block. – willydee Feb 24 '17 at 15:21
  • 1
    ARH. I read a guide saying the third parameter was number of retries. Turns out, it's actually timeout in jasmine `this.it = function(description, fn, timeout) {` – Ray Foss Mar 31 '20 at 16:59