fix(expect): name matcher in toMatchObject failure message#7142
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:
|
|
Thanks for the fix — the message is much clearer now. One cleanup before merge: export function buildEqualErrorMessage<T>(
actual: T,
expected: T,
options: EqualErrorMessageOptions & { header?: string } = {},
): string {
const { formatter = format, msg, header = "Values are not equal." } = options;
// ...
let message = `${msgPrefix}${header}`;
// ...
}Then Also: one optional nice-to-have in the test — assert that the diff body is actually present in the positive case (e.g. |
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