11/* istanbul ignore file */
22
3- import act , { getIsReactActEnvironment , setReactActEnvironment } from '../act' ;
3+ import { getIsReactActEnvironment , setReactActEnvironment } from '../act' ;
44import { flushMicroTasks } from '../flush-micro-tasks' ;
5- import { checkReactVersionAtLeast } from '../react-versions' ;
65
76/**
87 * Run given async callback with temporarily disabled `act` environment and flushes microtasks queue.
@@ -11,30 +10,15 @@ import { checkReactVersionAtLeast } from '../react-versions';
1110 * @returns Result of the callback
1211 */
1312export async function wrapAsync < Result > ( callback : ( ) => Promise < Result > ) : Promise < Result > {
14- if ( checkReactVersionAtLeast ( 18 , 0 ) ) {
15- const previousActEnvironment = getIsReactActEnvironment ( ) ;
16- setReactActEnvironment ( false ) ;
13+ const previousActEnvironment = getIsReactActEnvironment ( ) ;
14+ setReactActEnvironment ( false ) ;
1715
18- try {
19- const result = await callback ( ) ;
20- // Flush the microtask queue before restoring the `act` environment
21- await flushMicroTasks ( ) ;
22- return result ;
23- } finally {
24- setReactActEnvironment ( previousActEnvironment ) ;
25- }
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 ) ;
2623 }
27-
28- if ( ! checkReactVersionAtLeast ( 16 , 9 ) ) {
29- return callback ( ) ;
30- }
31-
32- // Wrapping with act for react version 16.9 to 17.x
33- let result : Result ;
34- await act ( async ( ) => {
35- result = await callback ( ) ;
36- } ) ;
37-
38- // Either we have result or `callback` threw error
39- return result ! ;
4024}
0 commit comments