Skip to content

Commit 4f421b3

Browse files
deokjinkimtargos
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 <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 1ac1fe4 commit 4f421b3

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/internal/test_runner/mock/mock_timers.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ const {
2626
} = primordials;
2727
const {
2828
validateAbortSignal,
29-
validateArray,
3029
validateNumber,
30+
validateStringArray,
3131
} = require('internal/validators');
3232

3333
const {
@@ -673,7 +673,7 @@ class MockTimers {
673673
*/
674674
/**
675675
* Enables the MockTimers replacing the native timers with the fake ones.
676-
* @param {EnableOptions} options
676+
* @param {EnableOptions} [options]
677677
*/
678678
enable(options = { __proto__: null, apis: SUPPORTED_APIS, now: 0 }) {
679679
const internalOptions = { __proto__: null, ...options };
@@ -693,7 +693,7 @@ class MockTimers {
693693
internalOptions.apis = SUPPORTED_APIS;
694694
}
695695

696-
validateArray(internalOptions.apis, 'options.apis');
696+
validateStringArray(internalOptions.apis, 'options.apis');
697697
// Check that the timers passed are supported
698698
ArrayPrototypeForEach(internalOptions.apis, (timer) => {
699699
if (!ArrayPrototypeIncludes(SUPPORTED_APIS, timer)) {

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

+8
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)