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

fix: Strict equality for errors and throws custom classes #13607

Closed
wants to merge 5 commits into from

Conversation

lpizzinidev
Copy link
Contributor

fix #13604

  • Handles strict equality checks for classes extending Error
  • Handles strict equality checks for custom classes in toThrow

return a.message == b.message;
// Compare just error messages only if not strict check
if (!strictCheck) return a.message == b.message;
if (a.message != b.message) return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems somewhat odd to me - should we stop comparing Errors unless their message matches? Is the thought that we want to treat that as any other objects?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the previous implementation, the discriminant determining Errors equality was only the message field.
With this implementation, you compare only the messages for non-strict equality, and you treat the two objects as any other object for strict equality checks.

It probably depends on how you think strict equality should be intended for Error objects.

@github-actions
Copy link

This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Mar 31, 2023
@github-actions
Copy link

This PR was closed because it has been stalled for 30 days with no activity. Please open a new PR if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this Apr 30, 2023
@github-actions
Copy link

This pull request 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 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: toThrow and toStrictEqual matchers compare only message field of errors
3 participants