diff --git a/lib/chai-as-promised.js b/lib/chai-as-promised.js index 0d0cb54..4ffdb2e 100644 --- a/lib/chai-as-promised.js +++ b/lib/chai-as-promised.js @@ -215,7 +215,10 @@ export default function (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 fc03fc1..7c2f23a 100644 --- a/test/assert-promise-specific.js +++ b/test/assert-promise-specific.js @@ -289,5 +289,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 ''" + }); + }); + }); }); });