Skip to content

test(approval-controller): assert the error codes the expectations describe - #10576

Merged
cryptodev-2s merged 1 commit into
mainfrom
test/approval-controller-assert-error-codes
Oct 14, 2026
Merged

cryptodev-2s merged 1 commit into
mainfrom
test/approval-controller-assert-error-codes

Conversation

@cryptodev-2s

@cryptodev-2s cryptodev-2s commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Explanation

getError returned a plain object, and toThrow given a plain object compares only its message. Every error code in this file was decoration: swapping one for a wrong value keeps the suite green.

These expectations now read the thrown error and assert message and code. The code is asserted unconditionally, so the paths that throw a plain Error are pinned to having none. Every code already in the file was correct, so nothing changes behaviourally, they are simply checked now.

rejects.toThrow(error) has the same blind spot for a custom Error subclass, so the one rejection path asserts the caller's error by identity instead.

Mutation checked: wrong code, unexpected code, missing code, nothing thrown, and a non Error all fail as they should.

References

  • Split out of the Vitest migration, where Vitest compares a thrown value strictly and the old shape cannot match at all. Landing it here on Jest keeps that migration mechanical: test: run approval-controller on Vitest #10549's diff for this file drops from roughly 280 changed lines to 19.

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
    • Not applicable, test only change. Carries the no-changelog label.
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them
    • None.

Note

Low Risk
Test-only changes to ApprovalController; no production code or runtime behavior changes.

Overview
ApprovalController tests now verify thrown errors’ messages and JSON-RPC code values, not only messages via Jest’s plain-object toThrow matching.

getError returns an ExpectedError descriptor (message + optional code), and a new expectToThrowError helper runs the operation once, catches the real Error, and asserts both fields (including code === undefined where no code is expected). Validation and “unknown id” cases across add, getApprovalCount, hasRequest, acceptRequest, rejectRequest, and updateRequestState were switched to this pattern.

The clearRequests rejection test now uses rejects.toBe(rejectionError) so the propagated JsonRpcError is checked by identity (and thus code), not only message/class via rejects.toThrow. oxlint-suppressions.json drops related lint suppressions for this test file.

Reviewed by Cursor Bugbot for commit bcbf6e0. Bugbot is set up for automated code reviews on this repo. Configure here.

@cryptodev-2s
cryptodev-2s requested a review from a team as a code owner September 29, 2026 14:39
@cryptodev-2s
cryptodev-2s deployed to default-branch September 29, 2026 14:39 — with GitHub Actions Active
@cryptodev-2s
cryptodev-2s added this pull request to stack #10578 September 29, 2026 14:41
OGPoyraz
OGPoyraz previously approved these changes Sep 29, 2026
@cryptodev-2s
cryptodev-2s force-pushed the test/approval-controller-assert-error-codes branch from c812b32 to bb0a88a Compare September 30, 2026 07:04
@cryptodev-2s
cryptodev-2s dismissed OGPoyraz’s stale review October 5, 2026 09:40

The merge-base changed after approval.

@cryptodev-2s
cryptodev-2s force-pushed the test/approval-controller-assert-error-codes branch from bb0a88a to 37d7aa9 Compare October 5, 2026 10:48
@cryptodev-2s
cryptodev-2s force-pushed the test/approval-controller-assert-error-codes branch 2 times, most recently from a91eb5e to 9404b82 Compare October 12, 2026 15:43
@cryptodev-2s
cryptodev-2s requested a review from OGPoyraz October 12, 2026 17:37
@cryptodev-2s
cryptodev-2s force-pushed the test/approval-controller-assert-error-codes branch from 9404b82 to bcbf6e0 Compare October 14, 2026 09:23
@cryptodev-2s
cryptodev-2s added this pull request to the merge queue Oct 14, 2026
Merged via the queue into main with commit 8eb3385 Oct 14, 2026
347 checks passed
@cryptodev-2s
cryptodev-2s deleted the test/approval-controller-assert-error-codes branch October 14, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants