Skip to content

fix(assert): hint at reference-equality when assertEquals diff is empty (#6878)#7158

Open
LeSingh1 wants to merge 2 commits into
denoland:mainfrom
LeSingh1:fix/6878-asserteq-reference-hint
Open

fix(assert): hint at reference-equality when assertEquals diff is empty (#6878)#7158
LeSingh1 wants to merge 2 commits into
denoland:mainfrom
LeSingh1:fix/6878-asserteq-reference-hint

Conversation

@LeSingh1
Copy link
Copy Markdown

Fixes #6878.

When assertEquals decides two values are unequal but they stringify identically (typically because a property is a function compared by reference), the rendered diff is empty:

error: AssertionError: Values are not equal.


    [Diff] Actual / Expected


    {
      x: 1,
      y: [Function: y],
    }

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 / removed entries. If not, append:

    Note: values stringify identically but are not structurally equal.
    Functions, Promises, Requests, Blobs, and other built-ins are compared by
    reference, so two distinct instances are never equal even when their
    representations match.

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 diffassertEquals({ x: 1 }, { x: 2 }) must NOT include the hint.
$ deno test --allow-read --allow-write assert/
ok | 141 passed (25 steps) | 0 failed (1s)

$ deno lint assert/equals.ts assert/equals_test.ts
Checked 2 files

$ deno check assert/equals.ts assert/equals_test.ts

…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
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.57%. Comparing base (f0c9f14) to head (c379203).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@std/assert/equals - assertEquals() fails with function properties without displaying why

1 participant