Skip to content

fix(snapshot): show focused diff for toMatchProperties mismatches#10009

Open
guoyangzhen wants to merge 1 commit intovitest-dev:mainfrom
guoyangzhen:fix/snapshot-properties-diff
Open

fix(snapshot): show focused diff for toMatchProperties mismatches#10009
guoyangzhen wants to merge 1 commit intovitest-dev:mainfrom
guoyangzhen:fix/snapshot-properties-diff

Conversation

@guoyangzhen
Copy link
Copy Markdown

Fixes #9985

When toMatchSnapshot(properties) fails due to a property mismatch, the diff previously showed the full received object with all its keys as additions, making it hard to identify the actual mismatched values.

For example, with expect({ x: 'world', y: 10 }).toMatchSnapshot({ y: 5 }), the diff showed:

{
-  "y": 5,
+  "x": "world",
+  "y": 10,
}

This made x look like an error when it's actually irrelevant to the properties check.

Fix: Filter the actual value to only include keys present in the expected properties object before returning the error. The diff now focuses on the values that actually differ:

{
-  "y": 5,
+  "y": 10,
}

…atches

When toMatchSnapshot(properties) fails due to a property mismatch,
the diff previously showed the full received object with all keys as
additions, making it hard to identify the actual mismatch.

This change filters the actual value to only include keys present in
the expected properties object, so the diff focuses on the values
that actually differ.
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 28, 2026

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 424c475
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/69c79e3a30ff220007f07334
😎 Deploy Preview https://deploy-preview-10009--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@sheremet-va sheremet-va added the maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control label Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maybe automated User is likely an AI agent, or the content was generated by an AI assistant without user control

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incomplete diff of toMatchSnapshot(properties) mismatch error

3 participants