Skip to content

test_runner: add [Symbol.dispose] to mock Timeout class#62879

Closed
HttpGetBinary wants to merge 1 commit intonodejs:mainfrom
HttpGetBinary:fix/mock-timers-symbol-dispose
Closed

test_runner: add [Symbol.dispose] to mock Timeout class#62879
HttpGetBinary wants to merge 1 commit intonodejs:mainfrom
HttpGetBinary:fix/mock-timers-symbol-dispose

Conversation

@HttpGetBinary
Copy link
Copy Markdown

Summary

Fixes #62815

The Timeout object returned by MockTimers was missing [Symbol.dispose], which means code using the using keyword with setTimeout would throw when mock timers are active.

Fix

Added [Symbol.dispose]() to the Timeout class in mock_timers.js. It calls globalThis.clearTimeout(this), which — when mocks are active — routes to the mock's own #clearTimeout, matching real Timeout behavior.

Test

// Should not throw
const t = mock.timers.enable({ apis: ['setTimeout'] });
{
  using timer = setTimeout(() => {}, 1000);
} // [Symbol.dispose] called here

The mock Timeout returned by MockTimers did not implement
[Symbol.dispose], making it incompatible with the `using`
keyword. The real Timeout has this method. This fix adds it,
calling globalThis.clearTimeout(this) which routes through
the mock's own clearTimeout when mocks are active.

Fixes: #62815
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem. labels Apr 21, 2026
@Renegade334
Copy link
Copy Markdown
Member

Please don't submit PRs against issues that already have open, active PRs.

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

Labels

needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MockTimers does not implement Timeout API correctl

3 participants