diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 0d6c5142..5670025f 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1456,6 +1456,16 @@ getJasmineRequireObj().pp = function(j$) { getJasmineRequireObj().QueueRunner = function(j$) { + function once(fn) { + var called = false; + return function() { + if (!called) { + called = true; + fn(); + } + }; + } + function QueueRunner(attrs) { this.fns = attrs.fns || []; this.onComplete = attrs.onComplete || function() {}; @@ -1503,10 +1513,10 @@ getJasmineRequireObj().QueueRunner = function(j$) { var clearTimeout = function () { Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeoutId]]); }, - next = function () { + next = once(function () { clearTimeout(timeoutId); self.run(fns, iterativeIndex + 1); - }, + }), timeoutId; if (self.enforceTimeout()) { diff --git a/spec/core/QueueRunnerSpec.js b/spec/core/QueueRunnerSpec.js index dd3090e5..37e651ee 100644 --- a/spec/core/QueueRunnerSpec.js +++ b/spec/core/QueueRunnerSpec.js @@ -172,6 +172,32 @@ describe("QueueRunner", function() { jasmine.clock().tick(j$.DEFAULT_TIMEOUT_INTERVAL); expect(onException).not.toHaveBeenCalled(); }); + + it("only moves to the next spec the first time you call done", function() { + var fn = function(done) {done(); done();}, + nextFn = jasmine.createSpy('nextFn'); + queueRunner = new j$.QueueRunner({ + fns: [fn, nextFn] + }); + + queueRunner.execute(); + expect(nextFn.calls.count()).toEqual(1); + }); + + it("does not move to the next spec if done is called after an exception has ended the spec", function() { + var fn = function(done) { + setTimeout(done, 1); + throw new Error('error!'); + }, + nextFn = jasmine.createSpy('nextFn'); + queueRunner = new j$.QueueRunner({ + fns: [fn, nextFn] + }); + + queueRunner.execute(); + jasmine.clock().tick(1); + expect(nextFn.calls.count()).toEqual(1); + }); }); it("calls an exception handler when an exception is thrown in a fn", function() { diff --git a/src/core/QueueRunner.js b/src/core/QueueRunner.js index f2f975ba..4a0e66f2 100644 --- a/src/core/QueueRunner.js +++ b/src/core/QueueRunner.js @@ -1,5 +1,15 @@ getJasmineRequireObj().QueueRunner = function(j$) { + function once(fn) { + var called = false; + return function() { + if (!called) { + called = true; + fn(); + } + }; + } + function QueueRunner(attrs) { this.fns = attrs.fns || []; this.onComplete = attrs.onComplete || function() {}; @@ -47,10 +57,10 @@ getJasmineRequireObj().QueueRunner = function(j$) { var clearTimeout = function () { Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeoutId]]); }, - next = function () { + next = once(function () { clearTimeout(timeoutId); self.run(fns, iterativeIndex + 1); - }, + }), timeoutId; if (self.enforceTimeout()) {