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 authored and Marco Ippolito committed 2024-08-19 10:32:48 +02:00
1 parent 0109f9c961
commit fb7342246c
2 files changed
+24 -1

No files matched your search

+1 -1
View File
@@ -301,7 +301,7 @@ class MockTimers {
}
#clearTimer(timer) {
if (timer.priorityQueuePosition !== undefined) {
if (timer?.priorityQueuePosition !== undefined) {
this.#executionQueue.removeAt(timer.priorityQueuePosition);
timer.priorityQueuePosition = undefined;
}
+23
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) => {