From 114498be6ed8f04d7a9272bd81fc43612d5c2cf5 Mon Sep 17 00:00:00 2001 From: Mattias Tidlund Date: Thu, 22 May 2014 22:54:02 +0200 Subject: [PATCH] Fix #1191 Make sure that a test case returning a promise fails if the promise is rejected without a reason. --- lib/runnable.js | 8 +++++++- test/runnable.js | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/runnable.js b/lib/runnable.js index 6940bb77d3..fce4c818d1 100644 --- a/lib/runnable.js +++ b/lib/runnable.js @@ -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(); } diff --git a/test/runnable.js b/test/runnable.js index 79b6ffb091..3ea7dc6ae0 100644 --- a/test/runnable.js +++ b/test/runnable.js @@ -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 () { }