Skip to content

📦🔥:describe any value in an assertion message - #94

Merged
openinf-commit-queue[bot] merged 1 commit into
mainfrom
claude/project-thread-2s9ymn-assert-messages
Oct 1, 2026
Merged

openinf-commit-queue[bot] merged 1 commit into
mainfrom
claude/project-thread-2s9ymn-assert-messages

Conversation

@DerekNonGeneric

@DerekNonGeneric DerekNonGeneric commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Requested by DerekNonGeneric

Before: assertEqual(Object.create(null), 1) threw TypeError: Cannot convert object to primitive value instead of an AssertionError. The same happened with the expectation of isEqualTo, isIdenticalTo and the four relational guard factories whenever the expected value had no prototype.

After: these messages describe the value the way assertValue already did, so the failed assertion is what gets reported.

How: assertValue's stringifyValue moves to _internal/_stringify-value.ts and every message builder uses it. Seven tests fail on main and pass here.

Summary by CodeRabbit

  • Bug Fixes
    • Assertion failures and comparison expectations now display values more reliably, including objects without prototypes, instead of throwing while formatting them.
    • Complex values use readable representations in messages; values that cannot be safely converted receive a fallback description.

assertEqual and six guard factories built their messages with String,
which throws a TypeError for an object without a prototype or one whose
toString throws. The assertion then failed with that TypeError rather
than an AssertionError naming what was expected.

assertValue already guarded against this, so its describer moves to an
internal module and every message uses it.

Signed-off-by: Derek Lewis <DerekNonGeneric@inf.is>
Assisted-by: Claude-Code:claude-opus-5
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: 40cdfba6-a10f-4121-a3a7-4eeb4842124a

📥 Commits

Reviewing files that changed from the base of the PR and between 45679ff and 48293e0.

📒 Files selected for processing (17)
  • .changeset/describe-any-expected-value.md
  • packages/assert/src/_internal/_stringify-value.ts
  • packages/assert/src/assertions/assert-equal.ts
  • packages/assert/src/assertions/assert-value.ts
  • packages/assert/src/guards/is-equal-to.ts
  • packages/assert/src/guards/is-greater-than-or-equal-to.ts
  • packages/assert/src/guards/is-greater-than.ts
  • packages/assert/src/guards/is-identical-to.ts
  • packages/assert/src/guards/is-less-than-or-equal-to.ts
  • packages/assert/src/guards/is-less-than.ts
  • packages/assert/test/assertions/assert-equal.ts
  • packages/assert/test/guards/is-equal-to.ts
  • packages/assert/test/guards/is-greater-than-or-equal-to.ts
  • packages/assert/test/guards/is-greater-than.ts
  • packages/assert/test/guards/is-identical-to.ts
  • packages/assert/test/guards/is-less-than-or-equal-to.ts
  • packages/assert/test/guards/is-less-than.ts

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour.


📝 Walkthrough

Walkthrough

The change adds a shared helper to format values in assertion failure messages and guard expectations. Equality and comparison logic remains unchanged. Tests cover null-prototype values, and a patch changeset describes the update.

Changes

Assertion value formatting

Layer / File(s) Summary
Shared value formatting
packages/assert/src/_internal/_stringify-value.ts, packages/assert/src/assertions/assert-value.ts
Adds _stringifyValue with string, JSON, and fallback formatting. assertValue uses the shared helper instead of its local formatter.
Assertion and guard message integrations
packages/assert/src/assertions/assert-equal.ts, packages/assert/src/guards/*, packages/assert/test/assertions/assert-equal.ts, packages/assert/test/guards/*, .changeset/describe-any-expected-value.md
assertEqual failure messages and guard expectations use _stringifyValue. Tests cover null-prototype values, and the changeset records the patch.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to 48293

This change makes assertion failure messages safe for values such as prototype-less objects, so they report an assertion error instead of a TypeError. No merge-blocking risk was identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 16 files. (1 skipped: 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: improving value descriptions in assertion messages.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Comment @coderabbitai help to get the list of available commands.

@DerekNonGeneric DerekNonGeneric self-assigned this Oct 1, 2026
@DerekNonGeneric DerekNonGeneric added the 🚀 Status: Commit Queue Land this pull request when its checks pass label Oct 1, 2026 — with Claude
@openinf-commit-queue
openinf-commit-queue Bot merged commit 9be2848 into main Oct 1, 2026
10 checks passed
@openinf-commit-queue openinf-commit-queue Bot removed the 🚀 Status: Commit Queue Land this pull request when its checks pass label Oct 1, 2026
@openinf-commit-queue
openinf-commit-queue Bot deleted the claude/project-thread-2s9ymn-assert-messages branch October 1, 2026 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant