Mirror: TypeScript LSP plugin that finds GraphQL documents in your code and provides diagnostics, auto-complete and hover-information.
at main 697 B view raw
1import { vi } from 'vitest'; 2 3type WaitForExpectOptions = { 4 timeout?: number; 5 interval?: number; 6}; 7 8export const waitForExpect = async ( 9 expectFn: () => void, 10 { interval = 2000, timeout = 30000 }: WaitForExpectOptions = {} 11) => { 12 // @sinonjs/fake-timers injects `clock` property into setTimeout 13 const usesFakeTimers = 'clock' in setTimeout; 14 15 if (usesFakeTimers) vi.useRealTimers(); 16 17 const start = Date.now(); 18 19 while (true) { 20 try { 21 expectFn(); 22 break; 23 } catch {} 24 25 if (Date.now() - start > timeout) { 26 throw new Error('Timeout'); 27 } 28 29 await new Promise(resolve => setTimeout(resolve, interval)); 30 } 31 32 if (usesFakeTimers) vi.useFakeTimers(); 33};