fix(assert): hint at reference-equality when assertEquals diff is empty (#6878)#7158
Open
LeSingh1 wants to merge 2 commits into
Open
fix(assert): hint at reference-equality when assertEquals diff is empty (#6878)#7158LeSingh1 wants to merge 2 commits into
LeSingh1 wants to merge 2 commits into
Conversation
…6878) `assertEquals` throws "Values are not equal" but renders an empty diff when actual/expected stringify identically yet are deemed unequal — the common case is a function property compared by reference. The empty diff leaves users hunting for invisible differences. Detect the case (diff result has zero `added`/`removed` entries) and append a one-line hint explaining that functions, Promises, Requests, Blobs, and other built-ins are compared by reference, so two distinct instances are never equal even when their representations match. Skip the hint on real textual diffs and on string-vs-string comparisons (which always produce visible add/remove if they differ). Two new tests cover the hint firing path and the negative case. Full assert suite (141 tests) stays green. Direction matches @lionel-rowe's suggestion in the issue thread.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7158 +/- ##
=======================================
Coverage 94.57% 94.57%
=======================================
Files 636 636
Lines 52138 52149 +11
Branches 9399 9403 +4
=======================================
+ Hits 49311 49322 +11
Misses 2249 2249
Partials 578 578 ☔ 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 #6878.
When
assertEqualsdecides two values are unequal but they stringify identically (typically because a property is a function compared by reference), the rendered diff is empty:That leaves users hunting for invisible differences. @lionel-rowe pointed at the underlying cause in the thread (functions, Promises, Requests, Blobs etc. fall back to reference equality) and suggested the diff should "explicitly state when there are invisible differences."
Fix
After building the diff, check whether it contains any
added/removedentries. If not, append:The hint is skipped on string-vs-string comparisons (which always produce a visible diff when they differ) and on real textual diffs (so existing failures aren't noisier).
Tests
Two cases in
assert/equals_test.ts:hints at reference-equality when objects with function props stringify identically (#6878)— reproduces the exact issue body's call and asserts the new hint text is present.does not append reference-equality hint when there is a real textual diff—assertEquals({ x: 1 }, { x: 2 })must NOT include the hint.