Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 77d00f9

Browse files
committed
Fix: Callback with an error even if Promise is rejected with nothing (closes #42)
1 parent cca775b commit 77d00f9

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ function asyncDone(fn, cb) {
2929
}
3030

3131
function onError(error) {
32+
if (!error) {
33+
error = new Error('Promise rejected without Error');
34+
}
3235
return done(error);
3336
}
3437

test/promises.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ function failure() {
1414
return when.reject(new Error('Promise Error'));
1515
}
1616

17+
function rejectNoError() {
18+
return when.reject();
19+
}
20+
1721
describe('promises', function() {
1822

1923
it('should handle a resolved promise', function(done) {
@@ -29,4 +33,12 @@ describe('promises', function() {
2933
done();
3034
});
3135
});
36+
37+
it('properly errors when rejected without an error', function(done) {
38+
asyncDone(rejectNoError, function(err) {
39+
expect(err).toExist();
40+
expect(err).toBeAn(Error);
41+
done();
42+
});
43+
});
3244
});

0 commit comments

Comments
 (0)