Add explicit fail and move on for async functions
- `done` now has a `fail` property which will call the global `fail` then continue to the next function in the queue [finish #73744618] Fix #567 Fix #568
This commit is contained in:
@@ -93,6 +93,28 @@ describe("QueueRunner", function() {
|
|||||||
expect(onComplete).toHaveBeenCalled();
|
expect(onComplete).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("explicitly fails an async function with a provided fail function and moves to the next function", function() {
|
||||||
|
var queueableFn1 = { fn: function(done) {
|
||||||
|
setTimeout(function() { done.fail('foo'); }, 100);
|
||||||
|
} },
|
||||||
|
queueableFn2 = { fn: jasmine.createSpy('fn2') },
|
||||||
|
failFn = jasmine.createSpy('fail'),
|
||||||
|
queueRunner = new j$.QueueRunner({
|
||||||
|
queueableFns: [queueableFn1, queueableFn2],
|
||||||
|
fail: failFn
|
||||||
|
});
|
||||||
|
|
||||||
|
queueRunner.execute();
|
||||||
|
|
||||||
|
expect(failFn).not.toHaveBeenCalled();
|
||||||
|
expect(queueableFn2.fn).not.toHaveBeenCalled();
|
||||||
|
|
||||||
|
jasmine.clock().tick(100);
|
||||||
|
|
||||||
|
expect(failFn).toHaveBeenCalledWith('foo');
|
||||||
|
expect(queueableFn2.fn).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it("sets a timeout if requested for asynchronous functions so they don't go on forever", function() {
|
it("sets a timeout if requested for asynchronous functions so they don't go on forever", function() {
|
||||||
var timeout = 3,
|
var timeout = 3,
|
||||||
beforeFn = { fn: function(done) { }, type: 'before', timeout: function() { return timeout; } },
|
beforeFn = { fn: function(done) { }, type: 'before', timeout: function() { return timeout; } },
|
||||||
|
|||||||
@@ -972,6 +972,12 @@ describe("Env integration", function() {
|
|||||||
message: 'Failed: messy message'
|
message: 'Failed: messy message'
|
||||||
})]
|
})]
|
||||||
}));
|
}));
|
||||||
|
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||||
|
description: 'fails via the done callback',
|
||||||
|
failedExpectations: [jasmine.objectContaining({
|
||||||
|
message: 'Failed: done failed'
|
||||||
|
})]
|
||||||
|
}));
|
||||||
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
|
||||||
description: 'has a message from an Error',
|
description: 'has a message from an Error',
|
||||||
failedExpectations: [jasmine.objectContaining({
|
failedExpectations: [jasmine.objectContaining({
|
||||||
@@ -997,6 +1003,12 @@ describe("Env integration", function() {
|
|||||||
}, 1);
|
}, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
env.it('fails via the done callback', function(innerDone) {
|
||||||
|
setTimeout(function() {
|
||||||
|
innerDone.fail('done failed');
|
||||||
|
}, 1);
|
||||||
|
});
|
||||||
|
|
||||||
env.it('has a message from an Error', function(innerDone) {
|
env.it('has a message from an Error', function(innerDone) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
env.fail(new Error('error message'));
|
env.fail(new Error('error message'));
|
||||||
|
|||||||
@@ -170,6 +170,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
options.catchException = catchException;
|
options.catchException = catchException;
|
||||||
options.clearStack = options.clearStack || clearStack;
|
options.clearStack = options.clearStack || clearStack;
|
||||||
options.timer = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
|
options.timer = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
|
||||||
|
options.fail = self.fail;
|
||||||
|
|
||||||
new j$.QueueRunner(options).execute();
|
new j$.QueueRunner(options).execute();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
this.catchException = attrs.catchException || function() { return true; };
|
this.catchException = attrs.catchException || function() { return true; };
|
||||||
this.userContext = attrs.userContext || {};
|
this.userContext = attrs.userContext || {};
|
||||||
this.timer = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
|
this.timer = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
|
||||||
|
this.fail = attrs.fail || function() {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueRunner.prototype.execute = function() {
|
QueueRunner.prototype.execute = function() {
|
||||||
@@ -63,6 +64,11 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
}),
|
}),
|
||||||
timeoutId;
|
timeoutId;
|
||||||
|
|
||||||
|
next.fail = function() {
|
||||||
|
self.fail.apply(null, arguments);
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
|
||||||
if (queueableFn.timeout) {
|
if (queueableFn.timeout) {
|
||||||
timeoutId = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() {
|
timeoutId = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() {
|
||||||
var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.');
|
var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.');
|
||||||
|
|||||||
Reference in New Issue
Block a user