test_runner: do not throw on mocked clearTimeout()

PR-URL: https://github.com/nodejs/node/pull/54005
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
Aksinya Bykova 2024-07-25 18:26:00 +03:00 committed by GitHub
parent 8c006d2d7a
commit 049c894350
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View File

@ -304,7 +304,7 @@ class MockTimers {
}
#clearTimer(timer) {
if (timer.priorityQueuePosition !== undefined) {
if (timer?.priorityQueuePosition !== undefined) {
this.#executionQueue.removeAt(timer.priorityQueuePosition);
timer.priorityQueuePosition = undefined;
}

View File

@ -257,6 +257,13 @@ describe('Mock Timers Test Suite', () => {
assert.strictEqual(fn.mock.callCount(), 0);
});
it('clearTimeout does not throw on null and undefined', (t) => {
t.mock.timers.enable({ apis: ['setTimeout'] });
nodeTimers.clearTimeout();
nodeTimers.clearTimeout(null);
});
});
describe('setInterval Suite', () => {
@ -305,6 +312,13 @@ describe('Mock Timers Test Suite', () => {
assert.strictEqual(fn.mock.callCount(), 0);
});
it('clearInterval does not throw on null and undefined', (t) => {
t.mock.timers.enable({ apis: ['setInterval'] });
nodeTimers.clearInterval();
nodeTimers.clearInterval(null);
});
});
describe('setImmediate Suite', () => {
@ -372,6 +386,15 @@ describe('Mock Timers Test Suite', () => {
});
});
describe('clearImmediate Suite', () => {
it('clearImmediate does not throw on null and undefined', (t) => {
t.mock.timers.enable({ apis: ['setImmediate'] });
nodeTimers.clearImmediate();
nodeTimers.clearImmediate(null);
});
});
describe('timers/promises', () => {
describe('setTimeout Suite', () => {
it('should advance in time and trigger timers when calling the .tick function multiple times', async (t) => {