Skip to content

Commit

Permalink
Fix: Callback with an error even if Promise is rejected with nothing (c…
Browse files Browse the repository at this point in the history
…loses #42)
  • Loading branch information
phated committed Aug 4, 2017
1 parent cca775b commit 77d00f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Expand Up @@ -29,6 +29,9 @@ function asyncDone(fn, cb) {
}

function onError(error) {
if (!error) {
error = new Error('Promise rejected without Error');
}
return done(error);
}

Expand Down
12 changes: 12 additions & 0 deletions test/promises.js
Expand Up @@ -14,6 +14,10 @@ function failure() {
return when.reject(new Error('Promise Error'));
}

function rejectNoError() {
return when.reject();
}

describe('promises', function() {

it('should handle a resolved promise', function(done) {
Expand All @@ -29,4 +33,12 @@ describe('promises', function() {
done();
});
});

it('properly errors when rejected without an error', function(done) {
asyncDone(rejectNoError, function(err) {
expect(err).toExist();
expect(err).toBeAn(Error);
done();
});
});
});

0 comments on commit 77d00f9

Please sign in to comment.