-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Feature]: Allow extending functionality of toEqual
#12880
Comments
Did you try using |
@ittays I could do that, but I'd much rather just be able to use That's kinda the biggest reason I want this feature, to avoid having to use many different matchers based on what I'm trying to compare is equal |
Got you. So if you're able to specify your special equality, you can still define your catch-it-all |
Yeah, I'd basically like to be able to use |
Any update/thoughts here? |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
We really need something like this because sometimes our connection pool ends up in an I.e. an assertion like: expect(book.authors).toEqual([a1]); When it fails will try to "kind of toJSON-but-not-really" We've made our own custom matcher that works around this, Kind of funny, for us its only a problem when the assertion fails and Jest tries to do the nifty diff of expected/actual; if the assertion passes, everything is just fine. Which makes it even easier for users to not realize they "should not use |
@ittays ☝️ ? |
While this feature ask specifically for toEqual, I'd like to stress out this: #7352 (comment) I am aware of a very burning use-cases for this = if you use (immutable) value-objects with non-trivial equality semantics (typically implemented using .compare / .equal functions, e.g. Synthetic example:
would work if you would register .equal-based equality tester in jest (qualified using instanceof, let's say)
|
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
@stephenpassero I have a rough and semi-working idea of how this could be solved using an enhancement. It allows you to register custom equality testers to the internal jasmine equal machinery. The tester first check for applicability (e.g. does object have equals function?) and if it's applicable it returns true/false, shortcircuit ing the default behavior. This applies also to toHave... mock matchers Downside is, my current version is crude and affects all tests, might be worth looking for help making it configurable even per-test or per test-file. Would you be willing to provide some review / alfa testing of this? |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Hello 👋 I've opened #13654 in an attempt to address this issue. Let me know what you think! Cheers! |
Thanks a lot @andrewiggins, this uses the same approach I attempted for my experimental hack! |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
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. |
🚀 Feature Proposal
I'd really like the ability to extend the
toEqual
matcher. In my case, I would like to call.equals
on each of my objects (if it exists), and otherwise resort to the default functionality. I saw this issue (#7351), but it kinda looked like it just stalled...Motivation
I may have mentioned some of this above, but I want the ability to add extra functionality to the
toEqual
matcher, without rewriting the entire thing.Example
Pitch
This allows users to extend equality checks as necessary, without large changes
The text was updated successfully, but these errors were encountered: