Skip to content

Commit

Permalink
Fix #1191
Browse files Browse the repository at this point in the history
Make sure that a test case returning a promise fails if the promise is rejected without a reason.
  • Loading branch information
mattias-lw committed May 22, 2014
1 parent bc708c1 commit 114498b
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 @@ -223,7 +223,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 114498b

Please sign in to comment.