Skip to content

Commit 92fa89f

Browse files
deokjinkimRafaelGSS
authored andcommitted
test_runner: use validateStringArray for timers.enable()
`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]>
1 parent 2cd8ef9 commit 92fa89f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/internal/test_runner/mock/mock_timers.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const {
2323

2424
const {
2525
validateAbortSignal,
26-
validateArray,
2726
validateNumber,
27+
validateStringArray,
2828
} = require('internal/validators');
2929

3030
const {
@@ -676,7 +676,7 @@ class MockTimers {
676676
*/
677677
/**
678678
* Enables the MockTimers replacing the native timers with the fake ones.
679-
* @param {EnableOptions} options
679+
* @param {EnableOptions} [options]
680680
*/
681681
enable(options = { __proto__: null, apis: SUPPORTED_APIS, now: 0 }) {
682682
const internalOptions = { __proto__: null, ...options };
@@ -696,7 +696,7 @@ class MockTimers {
696696
internalOptions.apis = SUPPORTED_APIS;
697697
}
698698

699-
validateArray(internalOptions.apis, 'options.apis');
699+
validateStringArray(internalOptions.apis, 'options.apis');
700700
// Check that the timers passed are supported
701701
ArrayPrototypeForEach(internalOptions.apis, (timer) => {
702702
if (!ArrayPrototypeIncludes(SUPPORTED_APIS, timer)) {

test/parallel/test-runner-mock-timers.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ describe('Mock Timers Test Suite', () => {
1717
});
1818
});
1919

20+
it('should throw an error if data type of trying to enable a timer is not string', (t) => {
21+
assert.throws(() => {
22+
t.mock.timers.enable({ apis: [1] });
23+
}, {
24+
code: 'ERR_INVALID_ARG_TYPE',
25+
});
26+
});
27+
2028
it('should throw an error if trying to enable a timer twice', (t) => {
2129
t.mock.timers.enable();
2230
assert.throws(() => {

0 commit comments

Comments
 (0)