Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rejectedWith when error is undefined doesn't work #263

Closed
fishcharlie opened this issue Mar 8, 2020 · 0 comments · Fixed by #294
Closed

rejectedWith when error is undefined doesn't work #263

fishcharlie opened this issue Mar 8, 2020 · 0 comments · Fixed by #294

Comments

@fishcharlie
Copy link

The following test doesn't work.

it("Should throw an error", async () => {
	return expect(Promise.reject()).to.be.rejectedWith("Error");
});

Instead of giving details about what went wrong (explaining that it expected the error to be "Error" but instead got undefined), it gives a very un-detailed internal error message as shown below:

TypeError: Cannot read property 'message' of undefined
   at Object.compatibleMessage (node_modules/check-error/index.js:78:71)
   at getBasePromise.then.reason (node_modules/chai-as-promised/lib/chai-as-promised.js:191:77)
43081j added a commit that referenced this issue May 13, 2024
When a promise is rejected, we currently incorrectly assume the
rejection reason is an object consumable by check-error (i.e. an `Error`
or similar).

This change basically checks strict equality on the matcher and the
thrown error first (such that `rejectedWith(undefined)` would work). It
then falls back to the original logic only if both the matcher and the
reason are truthy.

Fixes #263
43081j added a commit that referenced this issue May 13, 2024
When a promise is rejected, we currently incorrectly assume the
rejection reason is an object consumable by check-error (i.e. an `Error`
or similar).

This change basically checks strict equality on the matcher and the
thrown error first (such that `rejectedWith(undefined)` would work). It
then falls back to the original logic only if both the matcher and the
reason are truthy.

Fixes #263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant