diff --git a/lib/internal/test_runner/mock/mock_timers.js b/lib/internal/test_runner/mock/mock_timers.js index 2250d76ca5df56..1edef54bf3d91b 100644 --- a/lib/internal/test_runner/mock/mock_timers.js +++ b/lib/internal/test_runner/mock/mock_timers.js @@ -26,8 +26,8 @@ const { } = primordials; const { validateAbortSignal, - validateArray, validateNumber, + validateStringArray, } = require('internal/validators'); const { @@ -673,7 +673,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 }; @@ -693,7 +693,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(() => {