From aa15c0cf0dc568d8713e8bdd2febfef80d933dcc Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Thu, 7 Sep 2023 23:00:22 +0900 Subject: [PATCH] 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. --- lib/internal/test_runner/mock/mock_timers.js | 6 +++--- test/parallel/test-runner-mock-timers.js | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/internal/test_runner/mock/mock_timers.js b/lib/internal/test_runner/mock/mock_timers.js index 35c9a1ab68aac8..c0c55ce58a2a6c 100644 --- a/lib/internal/test_runner/mock/mock_timers.js +++ b/lib/internal/test_runner/mock/mock_timers.js @@ -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)) { diff --git a/test/parallel/test-runner-mock-timers.js b/test/parallel/test-runner-mock-timers.js index 6ce6c28c95e326..20440426556991 100644 --- a/test/parallel/test-runner-mock-timers.js +++ b/test/parallel/test-runner-mock-timers.js @@ -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(() => {