fix(expect): toMatchObject failure headline describes a subset match#7168
Open
LeSingh1 wants to merge 2 commits into
Open
fix(expect): toMatchObject failure headline describes a subset match#7168LeSingh1 wants to merge 2 commits into
LeSingh1 wants to merge 2 commits into
Conversation
expect(x).toMatchObject(y) is a subset check, not equality, so failing with "Values are not equal." misleads the reader (denoland#6999). Add an optional `summary` override to buildEqualErrorMessage and have toMatchObject pass "Object does not match the expected pattern." The diff body is unchanged and still produced by the same helper. toEqual and other equality matchers keep the original headline. Test pins the new headline and confirms the old one is no longer present. Fixes denoland#6999
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7168 +/- ##
==========================================
- Coverage 94.57% 94.57% -0.01%
==========================================
Files 636 636
Lines 52142 52145 +3
Branches 9401 9401
==========================================
+ Hits 49315 49317 +2
Misses 2249 2249
- Partials 578 579 +1 ☔ 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.
Fixes #6999.
expect(x).toMatchObject(y)is a subset check, not equality, so failing withValues are not equal.misleads the reader into thinking the test is asking for strict equality. From the issue's repro:After:
Implementation:
buildEqualErrorMessagenow accepts an optionalsummaryoverride on its options. Default is"Values are not equal."sotoEqualand the other equality matchers are unchanged.toMatchObjectpassessummary: "Object does not match the expected pattern."so the headline matches what it actually checks. The diff body and thecustomMessageprefix are untouched.Test added in
expect/_to_match_object_test.tspins the new headline and verifies the old one is no longer present. The full--filter toMatchObjectrun passes (7/7).