Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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();      }); }); 
like image 980
Brian Low Avatar asked Mar 26 '12 06:03

Brian Low


2 Answers

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;     }); }); 
like image 166
Francisco Avatar answered Sep 24 '22 06:09

Francisco


Sent pull request for this feature (https://github.com/mhevery/jasmine-node/pull/142)

it("cannot change timeout", function(done) {    request("http://localhost:3000/hello", function(error, response, body){       expect(body).toEqual("hello world");       done();   });  }, 5000); // set timeout to 5 seconds 
like image 35
Brian Low Avatar answered Sep 25 '22 06:09

Brian Low