Skip to content

test_runner: align MockTimers timeout API - #62820

Merged
nodejs-github-bot merged 2 commits into
nodejs:mainfrom
Han5991:fix/62815-mocktimers-timeout-api
Apr 23, 2026
Merged

nodejs-github-bot merged 2 commits into
nodejs:mainfrom
Han5991:fix/62815-mocktimers-timeout-api

Conversation

@Han5991

@Han5991 Han5991 commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Align MockTimers timeout handles with the public Timeout API by exposing close() and [Symbol.dispose]() on fake setTimeout() results.

Problem

When test.mock.timers.enable() is active, setTimeout() returns a mock timeout handle that does not implement Timeout.close() or Timeout[Symbol.dispose](). That breaks disposal-based patterns such as DisposableStack.use(timeout).

Root cause

MockTimers used its own Timeout wrapper with only ref(), unref(), refresh(), and hasRef(), so the fake timeout handle diverged from the documented timeout API.

Changes