Skip to content

Commit 45beb94

Browse files
deokjinkimeliphazbouye
authored andcommitted
doc: add missing supported timer values in timers.enable()
Some timer values such as `setImmediate` and `clearImmediate` are missed. And `milliseconds` which is argument of `timers.tick()` is optional and default is 1. Refs: nodejs#49534 (comment) PR-URL: nodejs#52969 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Moshe Atlow <[email protected]>
1 parent 5c1fb35 commit 45beb94

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

doc/api/test.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,8 @@ Enables timer mocking for the specified timers.
19941994
The currently supported timer values are `'setInterval'`, `'setTimeout'`, `'setImmediate'`,
19951995
and `'Date'`. **Default:** `['setInterval', 'setTimeout', 'setImmediate', 'Date']`.
19961996
If no array is provided, all time related APIs (`'setInterval'`, `'clearInterval'`,
1997-
`'setTimeout'`, `'clearTimeout'`, and `'Date'`) will be mocked by default.
1997+
`'setTimeout'`, `'clearTimeout'`, `'setImmediate'`, `'clearImmediate'`, and
1998+
`'Date'`) will be mocked by default.
19981999
* `now` {number | Date} An optional number or Date object representing the
19992000
initial time (in milliseconds) to use as the value
20002001
for `Date.now()`. **Default:** `0`.
@@ -2049,10 +2050,11 @@ mock.timers.enable({ apis: ['Date'], now: new Date() });
20492050

20502051
Alternatively, if you call `mock.timers.enable()` without any parameters:
20512052

2052-
All timers (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, and `'clearTimeout'`)
2053-
will be mocked. The `setInterval`, `clearInterval`, `setTimeout`, and `clearTimeout`
2054-
functions from `node:timers`, `node:timers/promises`,
2055-
and `globalThis` will be mocked. As well as the global `Date` object.
2053+
All timers (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, `'clearTimeout'`,
2054+
`'setImmediate'`, and `'clearImmediate'`) will be mocked. The `setInterval`,
2055+
`clearInterval`, `setTimeout`, `clearTimeout`, `setImmediate`, and
2056+
`clearImmediate` functions from `node:timers`, `node:timers/promises`, and
2057+
`globalThis` will be mocked. As well as the global `Date` object.
20562058

20572059
### `timers.reset()`
20582060

@@ -2083,7 +2085,7 @@ mock.timers.reset();
20832085

20842086
Calls `timers.reset()`.
20852087

2086-
### `timers.tick(milliseconds)`
2088+
### `timers.tick([milliseconds])`
20872089

20882090
<!-- YAML
20892091
added:
@@ -2094,7 +2096,7 @@ added:
20942096
Advances time for all mocked timers.
20952097

20962098
* `milliseconds` {number} The amount of time, in milliseconds,
2097-
to advance the timers.
2099+
to advance the timers. **Default:** `1`.
20982100

20992101
**Note:** This diverges from how `setTimeout` in Node.js behaves and accepts
21002102
only positive numbers. In Node.js, `setTimeout` with negative numbers is

0 commit comments

Comments
 (0)