jasmine: Allow done() to take an optional error.
It is a popular pattern to pass an error object to a done() callback in NodeJS.
We should support that in Jasmine 2.0, too so that users can properly unit test asynchronous code.
Example
describe('async with error', function() {
it('should fail on done(err)', function(done) {
setTimeout(function() {
done(new Error('async fail'));
}, 100);
});
});
should fail with
error: 'async fail'
instead of succeeding which is the case as of v2.0.0.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 24 (7 by maintainers)
Commits related to this issue
- Detect an Error passed to `done` and add an expectation failure - See #567 — committed to jasmine/jasmine by deleted user 6 years ago
Why not supporting done(err) as well? This is the nodejs way, forcing users to use something different makes absolutely no sense!
How about another variant that implements the node.js convention? It could be called something like done.node or done.expectNull.
I’m using this work around
expect(err.stack).toBeNull();+1 I switched to mocha because of that missing pattern