GeezerVison is showing github.com — test_runner: use validateStringArray for `timers.enable()` · nodejs/node@141e9fe
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 |
|---|
@@ -23,8 +23,8 @@ const { |
23 | 23 |
|
24 | 24 | const { |
25 | 25 | validateAbortSignal, |
26 | | - validateArray, |
27 | 26 | validateNumber, |
| 27 | + validateStringArray, |
28 | 28 | } = require('internal/validators'); |
29 | 29 |
|
30 | 30 | const { |
@@ -676,7 +676,7 @@ class MockTimers { |
676 | 676 | */ |
677 | 677 | /** |
678 | 678 | * Enables the MockTimers replacing the native timers with the fake ones. |
679 | | - * @param {EnableOptions} options |
| 679 | + * @param {EnableOptions} [options] |
680 | 680 | */ |
681 | 681 | enable(options = { __proto__: null, apis: SUPPORTED_APIS, now: 0 }) { |
682 | 682 | const internalOptions = { __proto__: null, ...options }; |
@@ -696,7 +696,7 @@ class MockTimers { |
696 | 696 | internalOptions.apis = SUPPORTED_APIS; |
697 | 697 | } |
698 | 698 |
|
699 | | - validateArray(internalOptions.apis, 'options.apis'); |
| 699 | + validateStringArray(internalOptions.apis, 'options.apis'); |
700 | 700 | // Check that the timers passed are supported |
701 | 701 | ArrayPrototypeForEach(internalOptions.apis, (timer) => { |
702 | 702 | 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(() => { |
|