Skip to content

Commit

Permalink
Document fake timer methods introduced in sinonjs/fake-timers#105 / s…
Browse files Browse the repository at this point in the history
  • Loading branch information
dominykas committed Jul 3, 2019
1 parent afc077f commit 6e0d9e5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions docs/release-source/release/fake-timers.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,30 @@ Please refer to the `lolex.install` [documentation](https://github.com/sinonjs/l
`var clock = sinon.useFakeTimers([now, ]prop1, prop2, ...)` is no longer supported. To define which methods to fake, please use `config.toFake`.


#### `clock.tick(time);`
#### `clock.tick(time);` / `await clock.tickAsync(time)`

Tick the clock ahead `time` milliseconds.

Causes all timers scheduled within the affected time range to be called. `time` may be the number of milliseconds to advance the clock by or a human-readable string. Valid string formats are "08" for eight seconds, "01:00" for one minute and "02:34:10" for two hours, 34 minutes and ten seconds.

time may be negative, which causes the clock to change but won't fire any callbacks.
`time` may be negative, which causes the clock to change but won't fire any callbacks.

#### `clock.next();`
The `tickAsync()` will also break the event loop, allowing any scheduled promise callbacks to execute _before_ running the timers.

#### `clock.next();` / `await clock.nextAsync()`

Advances the clock to the the moment of the first scheduled timer, firing it.

#### `clock.runAll();`
The `nextAsync()` will also break the event loop, allowing any scheduled promise callbacks to execute _before_ running the timers.

#### `clock.runAll();` / `await clock.runAllAsync()`

This runs all pending timers until there are none remaining. If new timers are added while it is executing they will be run as well.

This makes it easier to run asynchronous tests to completion without worrying about the number of timers they use, or the delays in those timers.

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

#### `clock.restore();`

Restore the faked methods.
Expand Down

0 comments on commit 6e0d9e5

Please sign in to comment.