From afb86cc4d1e8de069eb0449b678bc68e931be4ee Mon Sep 17 00:00:00 2001 From: Guillaume Duboc Date: Tue, 25 Oct 2022 22:45:45 +0200 Subject: [PATCH] docs(api): add runAllAsyncTimer --- docs/api/index.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/api/index.md b/docs/api/index.md index b6196f688c07..101fefb0c811 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -2094,6 +2094,26 @@ Vitest provides utility functions to help you out through it's **vi** helper. Yo vi.runAllTimers() ``` +### vi.runAllAsyncTimers + +- **Type:** `() => Vitest` + + This method will asynchronously invoke every initiated timer until the timers queue is empty. It means that every timer called during `runAllAsyncTimers` will be fired. If you have an infinite interval, + it will throw after 10 000 tries. For example this will log `1, 2, 3`: + + ```ts + let i = 0 + setTimeout(() => console.log(++i)) + const interval = setInterval(() => { + console.log(++i) + if (i === 3) + clearInterval(interval) + + }, 50) + + await vi.runAllAsyncTimers() + ``` + ### vi.runOnlyPendingTimers - **Type:** `() => Vitest`