Skip to content

assert: surface prototype mismatch in deepStrictEqual diff#62944

Open
maruthang wants to merge 1 commit intonodejs:mainfrom
maruthang:fix-50397-deepstrictequal-prototype-diff
Open

assert: surface prototype mismatch in deepStrictEqual diff#62944
maruthang wants to merge 1 commit intonodejs:mainfrom
maruthang:fix-50397-deepstrictequal-prototype-diff

Conversation

@maruthang
Copy link
Copy Markdown

When two values share the same enumerable shape but have different
prototypes, the diff produced by assert.deepStrictEqual rendered
the misleading Values have same structure but are not reference-equal: {} message, leaving the user without a hint that
the prototype is the differentiator.

Add an explicit Object prototypes differ: <actualProto> !== <expectedProto> line above the inspected body when the operator is
deepStrictEqual or partialDeepStrictEqual and the top-level
prototypes differ. Other operators (e.g., strictEqual([], []))
keep their existing notIdentical fallback message.

Fixes: #50397

Note: I was unable to run the test suite locally (no built out/Release/node on this Windows host). Both files pass node --check; the fix logic was verified in a standalone harness that exercises the patched branch. Looking forward to CI verification.

When two values share the same enumerable shape but have different
prototypes, the diff produced by `assert.deepStrictEqual` rendered
the misleading `Values have same structure but are not
reference-equal: {}` message, leaving the user without a hint that
the prototype is the differentiator.

Add an explicit `Object prototypes differ: <actualProto> !==
<expectedProto>` line above the inspected body when the operator is
`deepStrictEqual` or `partialDeepStrictEqual` and the top-level
prototypes differ. Other operators (e.g., `strictEqual([], [])`)
keep their existing `notIdentical` fallback message.

Fixes: nodejs#50397
Signed-off-by: Maruthan G <[email protected]>
@nodejs-github-bot nodejs-github-bot added assert Issues and PRs related to the assert subsystem. needs-ci PRs that need a full CI run. labels Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

assert Issues and PRs related to the assert subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

deepStrictEqual diff is unhelpful when prototype mismatches

2 participants