Skip to content

Commit 141e9fe

Browse files
deokjinkimRafaelGSS
authored andcommitted
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. PR-URL: #49534 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent e70711e commit 141e9fe

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎lib/internal/test_runner/mock/mock_timers.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ const {
2323

2424
const{
2525
validateAbortSignal,
26-
validateArray,
2726
validateNumber,
27+
validateStringArray,
2828
}=require('internal/validators');
2929

3030
const{
@@ -676,7 +676,7 @@ class MockTimers {
676676
*/
677677
/**
678678
* Enables the MockTimers replacing the native timers with the fake ones.
679-
* @param {EnableOptions} options
679+
* @param {EnableOptions} [options]
680680
*/
681681
enable(options={__proto__: null,apis: SUPPORTED_APIS,now: 0}){
682682
constinternalOptions={__proto__: null, ...options};
@@ -696,7 +696,7 @@ class MockTimers {
696696
internalOptions.apis=SUPPORTED_APIS;
697697
}
698698

699-
validateArray(internalOptions.apis,'options.apis');
699+
validateStringArray(internalOptions.apis,'options.apis');
700700
// Check that the timers passed are supported
701701
ArrayPrototypeForEach(internalOptions.apis,(timer)=>{
702702
if(!ArrayPrototypeIncludes(SUPPORTED_APIS,timer)){

‎test/parallel/test-runner-mock-timers.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ describe('Mock Timers Test Suite', () => {
1717
});
1818
});
1919

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+
2028
it('should throw an error if trying to enable a timer twice',(t)=>{
2129
t.mock.timers.enable();
2230
assert.throws(()=>{

0 commit comments

Comments
 (0)