-
-
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] Add support for custom equality testers #13654
Merged
Merged
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
63d7186
Add customEqualityTesters support to toEqual
andrewiggins 8f1daca
Add support for custom testers in iterableEquality
andrewiggins 45243cd
Add customTester support to toContainEqual and toHaveProperty
andrewiggins cb73a20
Add customTester support toStrictEqual
andrewiggins ce6aca4
Add customTester support to toMatchObject
andrewiggins b5684ce
Add customTesters to asymmetric matchers
andrewiggins 2fa1336
Add customTesters to spy matchers
andrewiggins e414bcc
Add test for custom matcher
andrewiggins 944934f
Clean up new tests a bit
andrewiggins 8a8bc17
Add support for customTesters to matcher recommendations in errors
andrewiggins 1ee862f
Give custom testers higher priority over built-in testers
andrewiggins 3961c37
Add custom testers to getObjectSubset
andrewiggins 7bdcded
Add CHANGELOG entry
andrewiggins 144f351
Fix customEqualityTesters TS errors
andrewiggins 1c9b629
Update packages/expect/src/__tests__/customEqualityTesters.test.ts
andrewiggins 9998279
Change API to addEqualityTesters
andrewiggins 9fcf9b5
Get customTesters from matcherContext
andrewiggins a791dcb
Rename customTesters to filteredCustomTesters
andrewiggins 32d0e38
Add type tests for new API
andrewiggins 05eca9f
Merge branch 'main' into custom-tester-extensions
SimenB b72796b
Merge branch 'main' into custom-tester-extensions
andrewiggins c9dc27c
Add docs, pt. 1
andrewiggins d22295b
Reorganize code to obsolete eslint ignore
andrewiggins 8591181
Convert custom equal testers tests to use Volume object matching docs
andrewiggins e88fff2
Finish out ExpectAPI docs and add recursive equality tester test
andrewiggins bed9a1e
reorganize
SimenB 15e509c
link in changelog
SimenB 96de10d
link section
SimenB dea4949
Expose equals function on tester context
andrewiggins 90afadb
Re-export Tester and TesterContext in expect package
andrewiggins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we ask people to use
this.equals
instead of importing it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be happy to, but currently customTesters are called without any
this
context (source from this PR). Custom testers are invoked byequals
in the expect-utils package and so don't have access to the matcher context.One idea to avoid importing encouraging importing
equals
would be to create an EqualityTesterContext withequals
and invoke equality testers with that, similar to what we do for matchers and MatchContext. Should I do that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, that makes sense! Yeah, I think we should have a context with at least
equals
(maybe only that for now?). That way, if people publish custom equality testers, they don't need to care what version of Jest people are using (beyond 29.4+) when we release 30, 31 etc..There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice! Yea, that makes sense. I believe the latest changes I've pushed do this. Let me know if you see anything else missing!
I've also re-exported the
Tester
andTesterContext
types from theexpect
package. My thinking was that since those types are implicitly exposed throughexpect.addEqualityTester
, explicitly exporting them would make using TypeScript a little easier and better mirror what people can do withexpect.extend
with theMatcherFunction
andMatcherContext
types. However, if you'd prefer people importTester
andTesterContext
directly from@jest/expect-utils
, we can simply revert that commit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good 👍