Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_runner: do not throw on mocked clearTimeout() #54005

Merged
merged 1 commit into from
Jul 25, 2024
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
2 changes: 1 addition & 1 deletion lib/internal/test_runner/mock/mock_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class MockTimers {
}

#clearTimer(timer) {
if (timer.priorityQueuePosition !== undefined) {
if (timer?.priorityQueuePosition !== undefined) {
this.#executionQueue.removeAt(timer.priorityQueuePosition);
timer.priorityQueuePosition = undefined;
}
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-runner-mock-timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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) => {
Expand Down
Loading