Search code examples
javascriptbddbuster.js

Buster JS - BDD style - set spec timeout


Using buster.js for BDD in javascript, I have some fairly hefty APIs to test. The default timeout isn't doing it for me under certain conditions. How do I override the default timeout for an (asynchronous) spec?

describe("Given a request for all combinations", function() {

    var scenario = null, spec;

    beforeAll(function() {
        scenario = scenarios.buildFakeAPI();
    });

    before(function(done) {

       spec = this;

       // *** this request can take up to 60 seconds which causes a timeout:
       scenario.request({ path: "/my/request/path" }, function(err, res) {

           spec.result = res;
           done();
       }); 
    });

    it("it should have returned the expected thing", function() {
        expect(spec.result).toMatch(/expected thing/);
    });
});

Solution

  • I had the same problem, and the following seemed to solved it.

    When not using BDD, one would set the timeout in the setUp function

    buster.testCase("MyTest", {
        setUp: function() {
            this.timeout = 1000; // 1000 ms ~ 1 s
        }
    });
    

    When using the BDD-notation, we can do the same in the beforeAll function

    describe("MyTest", function() {
        before(function() {
            this.timeout = 1000 * 60; // 60000 ms ~ 60 s
        });
    });