From 6e0d9e519595e8914605c902301b41ecab1c4fc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Blyz=CC=8Ce=CC=87?= Date: Thu, 4 Jul 2019 00:50:49 +0300 Subject: [PATCH] Document fake timer methods introduced in https://github.com/sinonjs/lolex/pull/105 / https://github.com/sinonjs/lolex/pull/237 --- docs/release-source/release/fake-timers.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/release-source/release/fake-timers.md b/docs/release-source/release/fake-timers.md index 8563b0606..6d7f647ea 100644 --- a/docs/release-source/release/fake-timers.md +++ b/docs/release-source/release/fake-timers.md @@ -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.