Skip to content

Commit

Permalink
Merge pull request #1224 from mattias-lw/fix_issue_1191
Browse files Browse the repository at this point in the history
Fix #1191 - Tests succeed on rejected falsey promises
  • Loading branch information
jonathanong committed Jul 8, 2014
2 parents 7ac4f01 + 114498b commit d5d1371
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/runnable.js
Expand Up @@ -224,7 +224,13 @@ Runnable.prototype.run = function(fn){
var result = fn.call(ctx);
if (result && typeof result.then === 'function') {
self.resetTimeout();
result.then(function(){ done() }, done);
result
.then(function() {
done()
},
function(reason) {
done(reason || new Error('Promise rejected with no or falsy reason'))
});
} else {
done();
}
Expand Down
22 changes: 22 additions & 0 deletions test/runnable.js
Expand Up @@ -299,6 +299,28 @@ describe('Runnable(title, fn)', function(){
})
})

describe('when the promise is rejected without a reason', function(){
var expectedErr = new Error('Promise rejected with no or falsy reason');
var rejectedPromise = {
then: function (fulfilled, rejected) {
process.nextTick(function () {
rejected();
});
}
};

it('should invoke the callback', function(done){
var test = new Runnable('foo', function(){
return rejectedPromise;
});

test.run(function(err){
err.should.eql(expectedErr);
done();
});
})
})

describe('when the promise takes too long to settle', function(){
var foreverPendingPromise = {
then: function () { }
Expand Down

0 comments on commit d5d1371

Please sign in to comment.