fix(assert): hint that function properties compare by reference#7165
Open
LeSingh1 wants to merge 1 commit into
Open
fix(assert): hint that function properties compare by reference#7165LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
assertEquals throws on inputs that only differ in a function property, but the diff prints both sides as the same [Function: name] string, which makes the failure look like "both sides identical, why did it throw?". Detect function values anywhere in either operand (own properties, array entries, Map values, Set elements; cycle-safe) and prepend a short note explaining that functions compare by reference. No change to the diff itself or to equality semantics. Fixes denoland#6878
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7165 +/- ##
==========================================
- Coverage 94.57% 94.57% -0.01%
==========================================
Files 636 636
Lines 52142 52178 +36
Branches 9401 9417 +16
==========================================
+ Hits 49315 49349 +34
Misses 2249 2249
- Partials 578 580 +2 ☔ 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
assertEqualsthrows on inputs that only differ in a function property, the diff prints both sides as the same[Function: name]string. The failure then looks like "both sides are identical, why did this throw?".Repro from the issue:
Before:
After:
Implementation: a small
containsFunctionwalker checks own properties, array entries, Map values, and Set elements (cycle-safe via aWeakSet) and the hint is appended only when at least one operand contains a function. No change to equality semantics or to the diff itself.Tests cover: the issue's object case, arrays of functions, and a negative case confirming the hint does not appear for function-free inputs. Full
assert/suite (140 tests) passes.