/** * To be used with jest fake timers. Will advance timers according to passed config, * while flushing out resolved promises to ensure that the Promise returned by given `fn` * will be fulfilled and its result collected. * * For example, if you have the current functions defined and you call `await fn1()`, * we have to flush pending promises out 3 times, even though all the functions are * ready to return immediately without passing any time, because they don't really do anything async. * ``` * async fn3() { return } * async fn2() { await fn3() } * async fn1(){ await fn2() } * ``` * * See more on this at https://stackoverflow.com/questions/52177631/jest-timer-and-promise-dont-work-well-settimeout-and-async-function * @param fn Async function you wish to test * @param jest Jest, to be passed from the test calling this function. * @param config * @returns `resolved` will be true if Promise returned `fn` was fulfilled. */ declare const waitForPromiseFn: (fn: any, jest: any, { advanceBeforeMs, advanceEveryLoopMs, maxRetries }: { advanceBeforeMs: any; advanceEveryLoopMs: any; maxRetries: any; }) => Promise<{ resolved: boolean; result: any; }>; /** * Flushes pending promises from promise jobs queue. Use in a test with fake timers when there's a promise that should have been * resolved by now (considering passage of faked time) but is not yet. * * In essence, enables whichever callers were waiting for Promises that have been resolved to get their * `then` callbacks called, or that is, their `await` to finish waiting and to be able to continue * code execution. * * Warning: Do not wrap this function into other async functions, otherwise it will stop working as expected. * It might work unpredictably that alter the way promises work, e.g. with packages like bluebird. * * See more on this at https://stackoverflow.com/questions/52177631/jest-timer-and-promise-dont-work-well-settimeout-and-async-function * @param flushCount Number of times to flush. In some cases with nested promises (in any async fn using `await` and only then return), it is necessary to flush multiple times for all of them to resolve. */ declare const flushPendingPromises: (flushCount?: number) => Promise; export { flushPendingPromises, waitForPromiseFn };