Detect an Error passed to done and add an expectation failure

- See #567
This commit is contained in:
Gregg Van Hove
2018-01-29 16:46:30 -08:00
parent 262a2fe674
commit 46cc48ccfa
6 changed files with 107 additions and 56 deletions

View File

@@ -135,6 +135,29 @@ describe("QueueRunner", function() {
expect(queueableFn2.fn).toHaveBeenCalled();
});
it("explicitly fails an async function when next is called with an Error and moves to the next function", function() {
var err = new Error('foo'),
queueableFn1 = { fn: function(done) {
setTimeout(function() { done(err); }, 100);
} },
queueableFn2 = { fn: jasmine.createSpy('fn2') },
failFn = jasmine.createSpy('fail'),
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn1, queueableFn2],
fail: failFn
});
queueRunner.execute();
expect(failFn).not.toHaveBeenCalled();
expect(queueableFn2.fn).not.toHaveBeenCalled();
jasmine.clock().tick(100);
expect(failFn).toHaveBeenCalledWith(err);
expect(queueableFn2.fn).toHaveBeenCalled();
});
it("sets a timeout if requested for asynchronous functions so they don't go on forever", function() {
var timeout = 3,
beforeFn = { fn: function(done) { }, type: 'before', timeout: function() { return timeout; } },
@@ -522,6 +545,24 @@ describe("QueueRunner", function() {
expect(nextQueueableFn.fn).not.toHaveBeenCalled();
expect(cleanupFn.fn).toHaveBeenCalled();
});
it("skips to cleanup functions when next is called with an Error", function() {
var queueableFn = { fn: function(done) {
done(new Error('nope'));
} },
nextQueueableFn = { fn: jasmine.createSpy('nextFunction') },
cleanupFn = { fn: jasmine.createSpy('cleanup') },
queueRunner = new jasmineUnderTest.QueueRunner({
queueableFns: [queueableFn, nextQueueableFn],
cleanupFns: [cleanupFn],
completeOnFirstError: true,
});
queueRunner.execute();
jasmine.clock().tick();
expect(nextQueueableFn.fn).not.toHaveBeenCalled();
expect(cleanupFn.fn).toHaveBeenCalled();
});
});
});

View File

@@ -1205,30 +1205,21 @@ describe("Env integration", function() {
env.addReporter({
specDone: specDone,
jasmineDone: function() {
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
description: 'has a default message',
failedExpectations: [jasmine.objectContaining({
message: 'Failed'
})]
}));
expect(specDone).toHaveBeenCalledWith(jasmine.objectContaining({
description: 'specifies a message',
failedExpectations: [jasmine.objectContaining({
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({
description: 'has a message from an Error',
failedExpectations: [jasmine.objectContaining({
message: 'Failed: error message'
})]
}));
expect(specDone).toHaveFailedExpectationsForRunnable('failing has a default message',
['Failed']
);
expect(specDone).toHaveFailedExpectationsForRunnable('failing specifies a message',
['Failed: messy message']
);
expect(specDone).toHaveFailedExpectationsForRunnable('failing fails via the done callback',
['Failed: done failed']
);
expect(specDone).toHaveFailedExpectationsForRunnable('failing has a message from an Error',
['Failed: error message']
);
expect(specDone).toHaveFailedExpectationsForRunnable('failing has a message from an Error to done',
['Failed: done error']
);
jasmine.clock().tick(1);
realSetTimeout(done);
@@ -1274,6 +1265,15 @@ describe("Env integration", function() {
jasmine.clock().tick(1);
jasmine.clock().tick(1);
});
env.it('has a message from an Error to done', function(innerDone) {
setTimeout(function() {
innerDone(new Error('done error'));
}, 1);
jasmine.clock().tick(1);
jasmine.clock().tick(1);
jasmine.clock().tick(1);
});
});
env.execute();