MCPcopy
hub / github.com/google-gemini/gemini-cli / waitFor

Function waitFor

packages/cli/src/test-utils/async.ts:15–39  ·  view source on GitHub ↗
(
  assertion: () => void | Promise<void>,
  { timeout = 2000, interval = 50 } = {},
)

Source from the content-addressed store, hash-verified

13// The version of waitFor from vitest is still fine to use if you aren't waiting
14// for React state updates.
15export async function waitFor(
16 assertion: () => void | Promise<void>,
17 { timeout = 2000, interval = 50 } = {},
18): Promise<void> {
19 const startTime = Date.now();
20
21 while (true) {
22 try {
23 await assertion();
24 return;
25 } catch (error) {
26 if (Date.now() - startTime > timeout) {
27 throw error;
28 }
29
30 await act(async () => {
31 if (vi.isFakeTimers()) {
32 await vi.advanceTimersByTimeAsync(interval);
33 } else {
34 await new Promise((resolve) => setTimeout(resolve, interval));
35 }
36 });
37 }
38 }
39}

Calls

no outgoing calls

Tested by 1

setupProcessorHookFunction · 0.68