Skip to content

fix(expect): name matcher in toMatchObject failure message#7142

Open
fibibot wants to merge 1 commit into
mainfrom
orch/issue-90
Open

fix(expect): name matcher in toMatchObject failure message#7142
fibibot wants to merge 1 commit into
mainfrom
orch/issue-90

Conversation

@fibibot
Copy link
Copy Markdown

@fibibot fibibot commented May 15, 2026

Summary

expect(received).toMatchObject(expected) previously failed with
AssertionError: Values are not equal., and the .not.toMatchObject
branch produced Expected actual: ... not to be: .... Both are
misleading because toMatchObject is a superset check, not strict
equality.

The triggerError closure in expect/_matchers.ts reused
buildEqualErrorMessage / buildNotEqualErrorMessage from
expect/_build_message.ts. This change adds two matcher-specific
builders, buildToMatchObjectErrorMessage and
buildNotToMatchObjectErrorMessage, that emit Jest-style headers:

expect(received).toMatchObject(expected)

<diff>
expect(received).not.toMatchObject(expected)

Expected: not <expected>
Received: <received>

Both branches of toMatchObject are routed through the new builders.
The diff content (already trimmed to the subset by PR #7078) is
preserved.

Test plan

  • Updated expect/_to_match_object_test.ts "throws the correct
    error messages" case to assert on the new matcher-named prefix
    and explicitly reject the previous Values are not equal /
    not to be phrasings.
  • deno fmt --check passes for expect/.
  • deno lint passes for expect/.
  • deno test -A expect/ passes (167 passed, 0 failed).
  • Reproduced the original issue locally; failure message now reads
    expect(received).toMatchObject(expected) instead of Values are not equal..

Closes #6999
Closes bartlomieju/orchid-inbox#90

`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
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

❌ Patch coverage is 87.87879% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.60%. Comparing base (5ea9159) to head (d0288ca).

Files with missing lines Patch % Lines
expect/_build_message.ts 85.18% 0 Missing and 4 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expect(...).toMatchObject error is "AssertionError: Values are not equal." instead of

2 participants