Only clear stack when QueueRunner is done with its functions

This commit is contained in:
Davis W. Frank and Sheel Choksi
2013-07-03 15:20:45 -07:00
parent 34b8bf5fb0
commit 7f6b16ccf2
3 changed files with 28 additions and 22 deletions

View File

@@ -1311,9 +1311,8 @@ getJasmineRequireObj().QueueRunner = function() {
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
var fn = fns[iterativeIndex];
if (fn.length > 0) {
attempt(function() { fn.call(self, function() {
self.clearStack(function() { self.run(fns, iterativeIndex + 1); });
});
attempt(function() {
fn.call(self, function() { self.run(fns, iterativeIndex + 1); });
});
return;
} else {
@@ -1321,7 +1320,12 @@ getJasmineRequireObj().QueueRunner = function() {
}
}
if (iterativeIndex >= length) {
var runnerDone = iterativeIndex >= length,
hasBeenAsyncSpec = recursiveIndex > 0;
if (runnerDone && hasBeenAsyncSpec) {
this.clearStack(this.onComplete);
} else if(runnerDone) {
this.onComplete();
}

View File

@@ -115,21 +115,19 @@ describe("QueueRunner", function() {
expect(completeCallback).toHaveBeenCalled();
});
it("calls a provided stack clearing function when done with async specs", function() {
var fn = function(done) { done() },
completeCallback = jasmine.createSpy('completeCallback'),
clearStack = jasmine.createSpy('clearStack'),
queueRunner = new j$.QueueRunner({
fns: [fn],
clearStack: clearStack,
onComplete: completeCallback
});
clearStack.andCallFake(function(fn) { fn(); });
it("with an async spec, calls a provided stack clearing function when done", function() {
var asyncFn = function(done) { done() },
afterFn = jasmine.createSpy('afterFn'),
completeCallback = jasmine.createSpy('completeCallback'),
clearStack = jasmine.createSpy('clearStack'),
queueRunner = new j$.QueueRunner({
fns: [asyncFn, afterFn],
clearStack: clearStack,
onComplete: completeCallback
});
queueRunner.execute();
expect(clearStack).toHaveBeenCalled();
expect(completeCallback).toHaveBeenCalled();
expect(afterFn).toHaveBeenCalled();
expect(clearStack).toHaveBeenCalledWith(completeCallback);
});
});

View File

@@ -20,9 +20,8 @@ getJasmineRequireObj().QueueRunner = function() {
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
var fn = fns[iterativeIndex];
if (fn.length > 0) {
attempt(function() { fn.call(self, function() {
self.clearStack(function() { self.run(fns, iterativeIndex + 1); });
});
attempt(function() {
fn.call(self, function() { self.run(fns, iterativeIndex + 1); });
});
return;
} else {
@@ -30,7 +29,12 @@ getJasmineRequireObj().QueueRunner = function() {
}
}
if (iterativeIndex >= length) {
var runnerDone = iterativeIndex >= length,
hasBeenAsyncSpec = recursiveIndex > 0;
if (runnerDone && hasBeenAsyncSpec) {
this.clearStack(this.onComplete);
} else if(runnerDone) {
this.onComplete();
}