QueueRunner continues running functions in async case

Continue running functions even if an async spec throws an
exception during the synchronous portion of the spec
This commit is contained in:
Sheel Choksi
2013-07-07 21:00:07 -07:00
parent 7f6b16ccf2
commit ec7d58fce0
3 changed files with 26 additions and 4 deletions

View File

@@ -1311,10 +1311,13 @@ getJasmineRequireObj().QueueRunner = function() {
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
var fn = fns[iterativeIndex];
if (fn.length > 0) {
attempt(function() {
var attemptSuccessful = attempt(function() {
fn.call(self, function() { self.run(fns, iterativeIndex + 1); });
});
return;
if(attemptSuccessful) {
return;
}
} else {
attempt(function() { fn.call(self); });
}
@@ -1332,6 +1335,7 @@ getJasmineRequireObj().QueueRunner = function() {
function attempt(fn) {
try {
fn();
return true;
} catch (e) {
self.onException(e);
if (!self.catchException(e)) {
@@ -1339,6 +1343,7 @@ getJasmineRequireObj().QueueRunner = function() {
//use a finally block to close the loop in a nice way..
throw e;
}
return false;
}
}
};

View File

@@ -102,6 +102,18 @@ describe("QueueRunner", function() {
expect(function() { queueRunner.execute(); }).toThrow();
});
it("continues running the functions even after an exception is thrown in an async spec", function() {
var fn = function(done) { throw new Error("error"); },
nextFn = jasmine.createSpy("nextFunction");
queueRunner = new j$.QueueRunner({
fns: [fn, nextFn]
});
queueRunner.execute();
expect(nextFn).toHaveBeenCalled();
});
it("calls a provided complete callback when done", function() {
var fn = jasmine.createSpy('fn'),
completeCallback = jasmine.createSpy('completeCallback'),

View File

@@ -20,10 +20,13 @@ getJasmineRequireObj().QueueRunner = function() {
for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
var fn = fns[iterativeIndex];
if (fn.length > 0) {
attempt(function() {
var attemptSuccessful = attempt(function() {
fn.call(self, function() { self.run(fns, iterativeIndex + 1); });
});
return;
if(attemptSuccessful) {
return;
}
} else {
attempt(function() { fn.call(self); });
}
@@ -41,6 +44,7 @@ getJasmineRequireObj().QueueRunner = function() {
function attempt(fn) {
try {
fn();
return true;
} catch (e) {
self.onException(e);
if (!self.catchException(e)) {
@@ -48,6 +52,7 @@ getJasmineRequireObj().QueueRunner = function() {
//use a finally block to close the loop in a nice way..
throw e;
}
return false;
}
}
};