Don't allow calling the same done callback multiple times

[finishes #62585700][fixes #523]
This commit is contained in:
Greg Cobb and Sheel Choksi
2014-02-25 18:03:52 -08:00
parent 5aac3e3292
commit 640f94a1bd
3 changed files with 50 additions and 4 deletions

View File

@@ -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()) {

View File

@@ -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() {

View File

@@ -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()) {