(callback: () => Promise<Result>)
| 10 | * @returns Result of the callback |
| 11 | */ |
| 12 | export async function wrapAsync<Result>(callback: () => Promise<Result>): Promise<Result> { |
| 13 | const previousActEnvironment = getIsReactActEnvironment(); |
| 14 | setReactActEnvironment(false); |
| 15 | |
| 16 | try { |
| 17 | const result = await callback(); |
| 18 | // Flush the microtask queue before restoring the `act` environment |
| 19 | await flushMicroTasks(); |
| 20 | return result; |
| 21 | } finally { |
| 22 | setReactActEnvironment(previousActEnvironment); |
| 23 | } |
| 24 | } |
no test coverage detected
searching dependent graphs…