diff --git a/lib/chai-as-promised.js b/lib/chai-as-promised.js index c0dd173..841b8cf 100644 --- a/lib/chai-as-promised.js +++ b/lib/chai-as-promised.js @@ -215,7 +215,10 @@ module.exports = (chai, utils) => { : checkError.compatibleConstructor(reason, errorLike)); const errMsgMatcherCompatible = - errMsgMatcher && checkError.compatibleMessage(reason, errMsgMatcher); + errMsgMatcher === reason || + (errMsgMatcher && + reason && + checkError.compatibleMessage(reason, errMsgMatcher)); const reasonName = getReasonName(reason); diff --git a/test/assert-promise-specific.js b/test/assert-promise-specific.js index 2e1c34c..e75f639 100644 --- a/test/assert-promise-specific.js +++ b/test/assert-promise-specific.js @@ -291,5 +291,20 @@ describe('Assert interface:', () => { }); }); }); + + describe('with undefined error', () => { + beforeEach(() => { + promise = Promise.reject(); + }); + + describe('.isRejected(promise)', () => { + shouldPass(() => assert.isRejected(promise)); + shouldPass(() => assert.isRejected(promise, undefined)); + shouldFail({ + op: () => assert.isRejected(promise, 'Error'), + message: "to be rejected with an error including 'Error' but got ''" + }); + }); + }); }); });