diff --git a/lib/internal/test_runner/mock/fake_timers.js b/lib/internal/test_runner/mock/fake_timers.js index 2d7cf32e5b06d3..01b3cd38a12ef4 100644 --- a/lib/internal/test_runner/mock/fake_timers.js +++ b/lib/internal/test_runner/mock/fake_timers.js @@ -22,7 +22,7 @@ class Timers { const timer = { id: timerId, callback, - time: DateNow() + delay, + runAt: DateNow() + delay, interval: isInterval, args, }; @@ -59,11 +59,11 @@ class FakeTimers { for (const timer of timers.values()) { - if (!(this.now >= timer.time)) continue; + if (!(this.now >= timer.runAt)) continue; timer.callback(...timer.args); if (timer.interval) { - timer.time = this.now + (timer.time - this.now) % timer.args[0]; + timer.runAt = this.now + (timer.runAt - this.now) % timer.args[0]; continue; } diff --git a/lib/internal/test_runner/mock/mock.js b/lib/internal/test_runner/mock/mock.js index 7268fd6d89ca7d..63c59a129ebeba 100644 --- a/lib/internal/test_runner/mock/mock.js +++ b/lib/internal/test_runner/mock/mock.js @@ -50,10 +50,6 @@ class MockFunctionContext { return ArrayPrototypeSlice(this.#calls, 0); } - get fakeTimers() { - this.#fakeTimers ??= new FakeTimers(); - return this.#fakeTimers; - } callCount() { return this.#calls.length; } @@ -112,6 +108,12 @@ delete MockFunctionContext.prototype.nextImpl; class MockTracker { #mocks = []; + #fakeTimers; + + get fakeTimers() { + this.#fakeTimers ??= new FakeTimers(); + return this.#fakeTimers; + } fn( original = function() {},