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: use validateStringArray for timers.enable() #49534

Merged
merged 1 commit into from
Aug 19, 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
6 changes: 3 additions & 3 deletions lib/internal/test_runner/mock/mock_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const {

const {
validateAbortSignal,
validateArray,
validateNumber,
validateStringArray,
} = require('internal/validators');

const {
Expand Down Expand Up @@ -676,7 +676,7 @@ class MockTimers {
*/
/**
* Enables the MockTimers replacing the native timers with the fake ones.
* @param {EnableOptions} options
* @param {EnableOptions} [options]
*/
enable(options = { __proto__: null, apis: SUPPORTED_APIS, now: 0 }) {
const internalOptions = { __proto__: null, ...options };
Expand All @@ -696,7 +696,7 @@ class MockTimers {
internalOptions.apis = SUPPORTED_APIS;
}

validateArray(internalOptions.apis, 'options.apis');
validateStringArray(internalOptions.apis, 'options.apis');
// Check that the timers passed are supported
ArrayPrototypeForEach(internalOptions.apis, (timer) => {
if (!ArrayPrototypeIncludes(SUPPORTED_APIS, timer)) {
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-runner-mock-timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ describe('Mock Timers Test Suite', () => {
});
});

it('should throw an error if data type of trying to enable a timer is not string', (t) => {
assert.throws(() => {
t.mock.timers.enable({ apis: [1] });
}, {
code: 'ERR_INVALID_ARG_TYPE',
});
});

it('should throw an error if trying to enable a timer twice', (t) => {
t.mock.timers.enable();
assert.throws(() => {
Expand Down