GeezerVison is showing github.com — test_runner: use validateStringArray for `timers.enable()` · nodejs/node@4f421b3
File tree
Expand file treeCollapse file tree
Open diff view settings
lib/internal/test_runner/mock
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/test_runner/mock/mock_timers.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,8 +26,8 @@ const { |
26 | 26 | } = primordials; |
27 | 27 | const { |
28 | 28 | validateAbortSignal, |
29 | | - validateArray, |
30 | 29 | validateNumber, |
| 30 | + validateStringArray, |
31 | 31 | } = require('internal/validators'); |
32 | 32 |
|
33 | 33 | const { |
@@ -673,7 +673,7 @@ class MockTimers { |
673 | 673 | */ |
674 | 674 | /** |
675 | 675 | * Enables the MockTimers replacing the native timers with the fake ones. |
676 | | - * @param {EnableOptions} options |
| 676 | + * @param {EnableOptions} [options] |
677 | 677 | */ |
678 | 678 | enable(options = { __proto__: null, apis: SUPPORTED_APIS, now: 0 }) { |
679 | 679 | const internalOptions = { __proto__: null, ...options }; |
@@ -693,7 +693,7 @@ class MockTimers { |
693 | 693 | internalOptions.apis = SUPPORTED_APIS; |
694 | 694 | } |
695 | 695 |
|
696 | | - validateArray(internalOptions.apis, 'options.apis'); |
| 696 | + validateStringArray(internalOptions.apis, 'options.apis'); |
697 | 697 | // Check that the timers passed are supported |
698 | 698 | ArrayPrototypeForEach(internalOptions.apis, (timer) => { |
699 | 699 | if (!ArrayPrototypeIncludes(SUPPORTED_APIS, timer)) { |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-runner-mock-timers.js +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,6 +17,14 @@ describe('Mock Timers Test Suite', () => { |
17 | 17 | }); |
18 | 18 | }); |
19 | 19 |
|
| 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 | + |
20 | 28 | it('should throw an error if trying to enable a timer twice', (t) => { |
21 | 29 | t.mock.timers.enable(); |
22 | 30 | assert.throws(() => { |
|