mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
test_runner: set mock timer's interval undefined
prevent adding timer to execution queue if clearInterval() called PR-URL: https://github.com/nodejs/node/pull/59479 Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
parent
0a46aa9e5d
commit
ec8c73d6ca
|
|
@ -321,6 +321,7 @@ class MockTimers {
|
|||
if (timer?.priorityQueuePosition !== undefined) {
|
||||
this.#executionQueue.removeAt(timer.priorityQueuePosition);
|
||||
timer.priorityQueuePosition = undefined;
|
||||
timer.interval = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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', () => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user