How do I change the timeout on a jasmine-node async spec

Brian Low picture Brian Low · Mar 26, 2012 · Viewed 81.4k times · Source

How can I get this test to pass without resorting to runs/waitsFor blocks?

it("cannot change timeout", function(done) {

     request("http://localhost:3000/hello", function(error, response, body){

         expect(body).toEqual("hello world");

         done();
     });
});

Answer

Francisco picture Francisco · Dec 15, 2015

You can (now) set it directly in the spec, as per Jasmine docs.

describe("long asynchronous specs", function() {

    var originalTimeout;

    beforeEach(function() {
        originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
        jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
    });

    it("takes a long time", function(done) {
        setTimeout(function() {
            done();
        }, 9000);
    });

    afterEach(function() {
        jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
    });
});