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

toMatchObject pass on comparing different Error objects #3859

Closed
thymikee opened this issue Jun 19, 2017 · 5 comments
Closed

toMatchObject pass on comparing different Error objects #3859

thymikee opened this issue Jun 19, 2017 · 5 comments

Comments

@thymikee
Copy link
Collaborator

Do you want to request a feature or report a bug?
enhancement

What is the current behavior?
toMatchObject pass on comparing different Error objects.

repro
This test will pass:

test('toMatchObject passes on different Errors', () => {
  expect(new Error('foo')).toMatchObject(new Error('bar'));
});

What is the expected behavior?
toMatchObject should fail on comparing Errors and show a proper message.

Originally reported in: #3795

@anilreddykatta
Copy link
Contributor

@thymikee toMatchObject should compare Error objects too? Or it should just fail without comparing when we encounter Error objects?

@jseminck
Copy link
Contributor

jseminck commented Jul 7, 2017

@thymikee am I correct in assuming that these tests should pass:

test('toMatchObject passes on similar Errors', () => {
  expect(new Error('foo')).toMatchObject(new Error('foo'));
});

and

test('toMatchObject fails on different Errors', () => {
  expect(new Error('foo')).not.toMatchObject(new Error('bar'));
});

@thymikee
Copy link
Collaborator Author

thymikee commented Jul 7, 2017

Not yet, but in next Jest release.

@jseminck
Copy link
Contributor

jseminck commented Jul 7, 2017

Ah. I see there is an open PR already. I was investigating this issue as well as I assumed it was still open. Anyway added a comment on the PR instead.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants