8000 test_runner: set mocktimer's interval undefined when clearInterval called by hotpineapple · Pull Request #59479 · nodejs/node · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/internal/test_runner/mock/mock_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ class MockTimers {
if (timer?.priorityQueuePosition !== undefined) {
this.#executionQueue.removeAt(timer.priorityQueuePosition);
timer.priorityQueuePosition = undefined;
timer.interval = undefined;
}
}

Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-runner-mock-timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,27 @@ describe('Mock Timers Test Suite', () => {
// Should not throw
});
});

it('interval cleared inside callback should only fire once', (t) => {
t.mock.timers.enable();
const calls = [];

setInterval(() => {
calls.push('foo');
}, 10);
const timerId = setInterval(() => {
calls.push('bar');
clearInterval(timerId);
}, 10);

t.mock.timers.tick(10);
t.mock.timers.tick(10);

assert.deepStrictEqual(
calls,
['foo', 'bar', 'foo'],
);
});
});

describe('globals/timers', () => {
Expand Down
Loading
0