fix(expect): name matcher in toMatchObject failure message#7142
Open
fibibot wants to merge 1 commit into
Open
Conversation
`toMatchObject` previously routed its failure messages through `buildEqualErrorMessage` and `buildNotEqualErrorMessage`, so the prefix read "Values are not equal." (or "Expected actual: ... not to be: ..."), which is misleading for a superset check. Add dedicated builders that emit `expect(received).toMatchObject(expected)` (and the `.not.` variant), matching Jest's matcher-named output. Closes #6999
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7142 +/- ##
==========================================
- Coverage 94.61% 94.60% -0.01%
==========================================
Files 634 634
Lines 51830 51860 +30
Branches 9341 9345 +4
==========================================
+ Hits 49037 49063 +26
Misses 2218 2218
- Partials 575 579 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
expect(received).toMatchObject(expected)previously failed withAssertionError: Values are not equal., and the.not.toMatchObjectbranch produced
Expected actual: ... not to be: .... Both aremisleading because
toMatchObjectis a superset check, not strictequality.
The
triggerErrorclosure inexpect/_matchers.tsreusedbuildEqualErrorMessage/buildNotEqualErrorMessagefromexpect/_build_message.ts. This change adds two matcher-specificbuilders,
buildToMatchObjectErrorMessageandbuildNotToMatchObjectErrorMessage, that emit Jest-style headers:Both branches of
toMatchObjectare routed through the new builders.The diff content (already trimmed to the subset by PR #7078) is
preserved.
Test plan
expect/_to_match_object_test.ts"throws the correcterror messages" case to assert on the new matcher-named prefix
and explicitly reject the previous
Values are not equal/not to bephrasings.deno fmt --checkpasses forexpect/.deno lintpasses forexpect/.deno test -A expect/passes (167 passed, 0 failed).expect(received).toMatchObject(expected)instead ofValues are not equal..Closes #6999
Closes bartlomieju/orchid-inbox#90