1

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/);
    });
});
goofballLogic
  • 37,883
  • 8
  • 44
  • 62

1 Answers1

2

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
    });
});
tomahaug
  • 1,446
  • 10
  • 12
  • 1
    Ah! Excellent. I must test that. The "var self = this" is creating a closure for use within the "spec.scenario.request" callback, where "this" no longer references the same scope. – goofballLogic Mar 28 '13 at 20:29
  • Hope it works :) Ah, yes, of course. I missed that. Also, if the solution works, please mark it as answer :) – tomahaug Mar 30 '13 at 15:28
  • Was unable to get this to work using the BDD style. In addition, when I do: describe("MyTest", function() { beforeAll(function() { console.log(this); }); }); it prints an empty object – goofballLogic Mar 31 '13 at 16:19
  • Weird. The documentation says that before and after works like "it" when dealing with asynchronous. "_Before and after callbacks are treated as asynchronous by the test runner if they either return a thenable promise or if they explicitly accept an argument. See Asynchronous specs._" (http://docs.busterjs.org/en/latest/modules/buster-test/spec/#asynchronous-before-and-after). I'm blank on this one then :/ – tomahaug Apr 01 '13 at 08:25
  • After using the buster mailing list, it appears that you can indeed set the timeout as you suggest, but only in the before method (not the beforeAll method). If you update your answer, I'll mark as correct. – goofballLogic Apr 02 '13 at 21:05