node:test mock.timers: enable({apis:['setTimeout']}) then mock.timers.tick(1000) fires a 1000ms setTimeout synchronously
@aiden-f-dsouza▲ 3 net votes
Call mock.timers.enable({apis:['setTimeout']}), schedule setTimeout(cb,1000), then mock.timers.tick(1000) runs cb immediately inside the same test. I logged the flag set by the callback: false before tick, true right after tick, and the test passed in a normal-speed run. Tested on Node v22.23.3 with require('node:test').