Skip to content

Commit

Permalink
test_runner: change fakeTimers prop name
Browse files Browse the repository at this point in the history
Signed-off-by: Erick Wendel <erick.workspace@gmail.com>
  • Loading branch information
ErickWendel committed May 1, 2023
1 parent ac0fab3 commit e54a162
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/internal/test_runner/mock/fake_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Timers {
const timer = {
id: timerId,
callback,
time: DateNow() + delay,
runAt: DateNow() + delay,
interval: isInterval,
args,
};
Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 6 additions & 4 deletions lib/internal/test_runner/mock/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -112,6 +108,12 @@ delete MockFunctionContext.prototype.nextImpl;

class MockTracker {
#mocks = [];
#fakeTimers;

get fakeTimers() {
this.#fakeTimers ??= new FakeTimers();
return this.#fakeTimers;
}

fn(
original = function() {},
Expand Down

0 comments on commit e54a162

Please sign in to comment.