Describe the bug
FakeTime does not mock node:timers methods.
Steps to Reproduce
- Create
index.js file
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);
});
- Execute the command:
deno test index.js
- 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]]]) method.
Actual behavior
FakeTime does not mock the timersPromises.setTimeout() method.
Environment
- OS: Ubuntu 25.04
- deno version: 2.8.2
- std version:
Describe the bug
FakeTimedoes not mocknode:timersmethods.Steps to Reproduce
index.jsfiledeno test index.jsExpected behavior
FakeTime mock the
timersPromises.setTimeout([delay[, value[, options]]])method.Actual behavior
FakeTime does not mock the
timersPromises.setTimeout()method.Environment