Skip to content

Commit

Permalink
test_runner: use validateStringArray for timers.enable()
Browse files Browse the repository at this point in the history
`apis` which is argument of `timers.enable()` is string array.
So use `validatStringArray` instead of `validateArray`. And
`options` is optional, so update JSDoc.

PR-URL: #49534
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Zijian Liu <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
  • Loading branch information
deokjinkim authored and targos committed Sep 26, 2024
1 parent a90126f commit d4c84d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
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 @@ -26,8 +26,8 @@ const {
} = primordials;
const {
validateAbortSignal,
validateArray,
validateNumber,
validateStringArray,
} = require('internal/validators');

const {
Expand Down Expand Up @@ -673,7 +673,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 @@ -693,7 +693,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

0 comments on commit d4c84d2

Please sign in to comment.