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

后端 未结 10 1921
生来不讨喜
生来不讨喜 2020-12-04 20:53

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

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

     request(\"http://localhost:30         


        
相关标签:
10条回答
  • 2020-12-04 21:25

    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
    
    0 讨论(0)
  • 2020-12-04 21:26

    Put it after describe statement:

    describe("A saves to DB", function() {
        jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
    
    0 讨论(0)
  • 2020-12-04 21:26

    Why not by spying on setTimeout()?

    Something like:

    var spy = spyOn(window, 'setTimeout').andCallFake(function (func, timeout) {
        expect(timeout).toEqual(2500);
        func();
    });
    
    setTimeOut(function () { ... }, 2500);
    expect(spy).toHaveBeenCalled();
    
    0 讨论(0)
  • 2020-12-04 21:29

    Looks like you can now add it as the last argument for the it function:

    describe('my test', function(){
        it('works', function(done){
            somethingAsync().then(done);
        }, 10000); // changes to 10 seconds
    });
    
    0 讨论(0)
提交回复
热议问题