Skip to content

Commit 197d660

Browse files
committed
Update documentation on faking timers to reflect the current state of fake-timers
1 parent c5ddf80 commit 197d660

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

docs/release-source/release/fake-timers.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ As above, but allows further configuration options.
5959

6060
- `config.now` - _Number/Date_ - installs `fake-timers` with the specified unix epoch (default: 0)
6161
- `config.toFake` - _String[ ]_ - an array with explicit function names to fake. By default `fake-timers` will automatically fake _all_ methods (changed in v19).
62+
- `config.toNotFake` - _String[ ]_ - an array with explicit function names to **not** fake.
63+
- `config.loopLimit` - _Number_ - the maximum number of timers that will be run when calling `runAll()` before assuming an infinite loop and throwing an error (default: 1000).
6264
- `config.shouldAdvanceTime` - _Boolean_ - tells `fake-timers` to increment mocked time automatically based on the real system time shift (default: false). When used in conjunction with `config.toFake`, it will only work if `'setInterval'` is included in `config.toFake`.
65+
- `config.advanceTimeDelta` - _Number_ - increment (in ms) used when `shouldAdvanceTime` is true (default: 20).
66+
- `config.shouldClearNativeTimers` - _Boolean_ - if set to `true`, `fake-timers` will clear any native timers that were already scheduled when the fake timers are installed (default: false).
67+
- `config.ignoreMissingTimers` - _Boolean_ - if set to `true`, `fake-timers` will not throw an error if a method to fake is missing from the environment (default: false).
6368
- **`config.global`** - _Object_ - use `global` instead of the usual global object. This is useful if you use JSDOM along with Node.
6469

6570
The options are basically all of those supported by the `install()` method of our `fake-timers` library, with the sole exception of `global`.
@@ -178,6 +183,32 @@ This makes it easier to run asynchronous tests to completion without worrying ab
178183

179184
The `runAllAsync()` will also break the event loop, allowing any scheduled promise callbacks to execute _before_ running the timers.
180185

186+
#### `clock.runToLast();` / `await clock.runToLastAsync()`
187+
188+
This runs all pending timers until the last timer has been fired. If new timers are added while it is executing they will be run as well.
189+
190+
The `runToLastAsync()` will also break the event loop, allowing any scheduled promise callbacks to execute _before_ running the timers.
191+
192+
#### `clock.runToFrame();`
193+
194+
Advances the clock to the next animation frame (standard 16ms).
195+
196+
#### `clock.runMicrotasks();`
197+
198+
Runs all pending microtasks (e.g. `process.nextTick` or `Promise` callbacks).
199+
200+
#### `clock.countTimers();`
201+
202+
Returns the number of waiting timers.
203+
204+
#### `clock.setSystemTime([now]);`
205+
206+
This allows you to change the system time to the provided `now` (number or Date) without firing any timers.
207+
208+
#### `clock.reset();`
209+
210+
Resets the clock to its initial `now` value and clears all pending timers.
211+
181212
#### `clock.restore();`
182213

183214
Restore the faked methods.

src/sinon/util/fake-timers.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,11 @@ export const timers = {
8787
addIfDefined(timers, "setImmediate");
8888
addIfDefined(timers, "clearImmediate");
8989
addIfDefined(timers, "Temporal");
90+
addIfDefined(timers, "performance");
91+
addIfDefined(timers, "requestAnimationFrame");
92+
addIfDefined(timers, "cancelAnimationFrame");
93+
addIfDefined(timers, "requestIdleCallback");
94+
addIfDefined(timers, "cancelIdleCallback");
95+
addIfDefined(timers, "hrtime");
96+
addIfDefined(timers, "nextTick");
97+
addIfDefined(timers, "queueMicrotask");

0 commit comments

Comments
 (0)