Skip to content

Commit

Permalink
doc: add missing supported timer values in timers.enable()
Browse files Browse the repository at this point in the history
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: #49534 (comment)
PR-URL: #52969
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
  • Loading branch information
deokjinkim authored and targos committed May 21, 2024
1 parent 602da2d commit 77fd504
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,8 @@ Enables timer mocking for the specified timers.
The currently supported timer values are `'setInterval'`, `'setTimeout'`, `'setImmediate'`,
and `'Date'`. **Default:** `['setInterval', 'setTimeout', 'setImmediate', 'Date']`.
If no array is provided, all time related APIs (`'setInterval'`, `'clearInterval'`,
`'setTimeout'`, `'clearTimeout'`, and `'Date'`) will be mocked by default.
`'setTimeout'`, `'clearTimeout'`, `'setImmediate'`, `'clearImmediate'`, and
`'Date'`) will be mocked by default.
* `now` {number | Date} An optional number or Date object representing the
initial time (in milliseconds) to use as the value
for `Date.now()`. **Default:** `0`.
Expand Down Expand Up @@ -2038,10 +2039,11 @@ mock.timers.enable({ apis: ['Date'], now: new Date() });

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

All timers (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, and `'clearTimeout'`)
will be mocked. The `setInterval`, `clearInterval`, `setTimeout`, and `clearTimeout`
functions from `node:timers`, `node:timers/promises`,
and `globalThis` will be mocked. As well as the global `Date` object.
All timers (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, `'clearTimeout'`,
`'setImmediate'`, and `'clearImmediate'`) will be mocked. The `setInterval`,
`clearInterval`, `setTimeout`, `clearTimeout`, `setImmediate`, and
`clearImmediate` functions from `node:timers`, `node:timers/promises`, and
`globalThis` will be mocked. As well as the global `Date` object.

### `timers.reset()`

Expand Down Expand Up @@ -2072,7 +2074,7 @@ mock.timers.reset();

Calls `timers.reset()`.

### `timers.tick(milliseconds)`
### `timers.tick([milliseconds])`

<!-- YAML
added:
Expand All @@ -2083,7 +2085,7 @@ added:
Advances time for all mocked timers.

* `milliseconds` {number} The amount of time, in milliseconds,
to advance the timers.
to advance the timers. **Default:** `1`.

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

0 comments on commit 77fd504

Please sign in to comment.