UNPKG

1.13 kBTypeScriptView Raw
1type Falsy = false | 0 | '' | null | undefined;
2export interface Options {
3 timeout?: number;
4 timeoutMessage?: string;
5}
6/**
7 Wait for the provided callback to return a truthy value.
8
9 This does not leverage `settled()`, and as such can be used to manage async
10 while _not_ settled (e.g. "loading" or "pending" states).
11
12 @public
13 @param {Function} callback the callback to use for testing when waiting should stop
14 @param {Object} [options] options used to override defaults
15 @param {number} [options.timeout=1000] the maximum amount of time to wait
16 @param {string} [options.timeoutMessage='waitUntil timed out'] the message to use in the reject on timeout
17 @returns {Promise} resolves with the callback value when it returns a truthy value
18
19 @example
20 <caption>
21 Waiting until a selected element displays text:
22 </caption>
23 await waitUntil(function() {
24 return find('.my-selector').textContent.includes('something')
25 }, { timeout: 2000 })
26*/
27export default function waitUntil<T>(callback: () => T | void | Falsy, options?: Options): Promise<T>;
28export {};
29//# sourceMappingURL=wait-until.d.ts.map
\No newline at end of file