Soundorv0.13.0

waitFor

Retries an assertion until it passes: for storage, native calls and effects that settle later.

await waitFor(callback: () => T | Promise<T>, options?: { timeout?: number; interval?: number }): Promise<T>;

Calls callback until it stops throwing (or rejecting), and resolves with what it returned; after timeout it rejects with the last error. For what settles later: storage, files, native async methods, effects.

await user.keyboard('{Enter}');
await waitFor(async () => expect(await storage.get('presetName')).toBe('Warm'));
OptionDefaultWhat it is
timeout1000 msHow long to keep trying.
interval20 msHow long between tries.

The findBy… queries are waitFor around a getBy…: await screen.findByText('Saved').

Good to know

  • Assert inside, do not act: the callback runs many times; an action in it runs as many.
  • Animations do not move while it waits: their time is advanceTime's. Vitest's fake Node timers do advance.
  • For what is synchronous, assert directly: a click's result is there once await user.click(…) resolves.

On this page