`FakeTime` does not mock `node:timers` methods
- Dominant language
- TypeScript
- Stars
- 3.6k
- Forks
- 681
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
[`FakeTime`](https://jsr.io/@std/testing/doc/time/~/FakeTime) does not mock [`node:timers`](https://nodejs.org/api/timers.html) methods.
**Steps to Reproduce**
1. Create `index.js` file
```javascript
import { assertSpyCalls, spy } from "jsr:@std/testing/mock";
import { FakeTime } from "jsr:@std/testing/time";
import timers from "node:timers/promises";
Deno.test("with timers", async () => {
const init = async (cb) => {
await timers.setTimeout(1000);
cb();
};
using time = new FakeTime();
const cb = spy();
init(cb);
time.tick(1000);
await time.runMicrotasks();
assertSpyCalls(cb, 1);
});
Deno.test("with setTimeout", async () => {
const init = async (cb) => {
await new Promise((r) => setTimeout(r, 1000));
cb();
};
using time = new FakeTime();
const cb = spy();
init(cb);
time.tick(1000);
await time.runMicrotasks();
assertSpyCalls(cb, 1);
});
```
2. Execute the command: `deno test index.js`
3. See error
```
running 2 tests from ./index.js
with timers ... FAILED (3ms)
with setTimeout ... ok (16ms)
ERRORS
with timers => ./index.js:5:6
error: AssertionError: Spy not called as much as expected:
[Diff] Actual / Expected
- 0
+ 1
throw new AssertionError(message);
^
at assertSpyCalls (https://jsr.io/@std/testing/1.0.19/mock.ts:1190:11)
at file:///home/regseb/tmp/deno/index.js:18:5
FAILURES
with timers => ./index.js:5:6
FAILED | 1 passed | 1 failed (27ms)
error: Test failed
```
**Expected behavior**
FakeTime mock the [`timersPromises.setTimeout([delay[, value[, options]]])`](https://nodejs.org/api/timers.html#timerspromisessettimeoutdelay-value-options) method.
**Actual behavior**
FakeTime does not mock the `timersPromises.setTimeout()` method.
**Environment**
- OS: Ubuntu 25.04
- deno version: 2.8.2
- std version:
Contributor guide
Assessment
This issue has not been assessed yet.