mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
@@ -23,8 +23,8 @@ const {
|
||||
|
||||
const {
|
||||
validateAbortSignal,
|
||||
validateArray,
|
||||
validateNumber,
|
||||
validateStringArray,
|
||||
} = require('internal/validators');
|
||||
|
||||
const {
|
||||
@@ -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 };
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user