-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[Docs]: toThrow fails if error object contains a cause
property
#15072
Labels
Comments
This appears to occur in the synchronous case as well: expect(() => {
throw new Error('message', { cause: new Error('cause') });
}).toThrow(new Error('message')); output:
but doesn't occur if In summary: it("should pass, but doesn't, async case", async () => {
await expect(
(async () => {
throw new Error('message', { cause: new Error('cause') });
})(),
).rejects.toThrow(new Error('message'));
});
it("should pass, but doesn't, sync case", () => {
expect(() => {
throw new Error('message', { cause: new Error('cause') });
}).toThrow(new Error('message'));
});
it('should pass, does pass', () => {
expect(() => {
throw new Error('message', { cause: 'cause' });
}).toThrow(new Error('message'));
}); TBH it seems like this may be a bug, not just undocumented behavior |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Page(s)
https://jestjs.io/docs/expect#tothrowerror
Description
When attempting to use the
toThrow()
method to validate an exact error message, I expected the following code to pass, according to the docs.However, it fails with error
That's reasonable behavior, but it should be documented as such.
The text was updated successfully, but these errors were encountered: