diff --git a/lib/internal/test_runner/mock/mock_timers.js b/lib/internal/test_runner/mock/mock_timers.js index bacfbf41a207d6..400ca5e37f026e 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 3e8d2d79ede52b..e2a86a5263636a 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(() => {