File tree 3 files changed +29
-4
lines changed
3 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -3,3 +3,28 @@ import { setImmediate } from './helpers/timers';
3
3
export function flushMicroTasks ( ) {
4
4
return new Promise ( ( resolve ) => setImmediate ( resolve ) ) ;
5
5
}
6
+
7
+ /**
8
+ * @deprecated To be removed in the next major release.
9
+ */
10
+ type Thenable < T > = { then : ( callback : ( ) => T ) => unknown } ;
11
+
12
+ /**
13
+ * This legacy implementation of `flushMicroTasks` is used for compatibility with
14
+ * older versions of React Native (pre 0.71) which uses Promise polyfil.
15
+ *
16
+ * For users with older version of React Native there is a workaround of using our own
17
+ * Jest preset instead the `react-native` one, but requiring such change would be a
18
+ * breaking change for existing users.
19
+ *
20
+ * @deprecated To be removed in the next major release.
21
+ */
22
+ export function flushMicroTasksLegacy ( ) : Thenable < void > {
23
+ return {
24
+ // using "thenable" instead of a Promise, because otherwise it breaks when
25
+ // using "modern" fake timers
26
+ then ( resolve ) {
27
+ setImmediate ( resolve ) ;
28
+ } ,
29
+ } ;
30
+ }
Original file line number Diff line number Diff line change 1
1
import { cleanup } from './pure' ;
2
- import { flushMicroTasks } from './flushMicroTasks' ;
2
+ import { flushMicroTasksLegacy } from './flushMicroTasks' ;
3
3
import { getIsReactActEnvironment , setReactActEnvironment } from './act' ;
4
4
5
5
if ( typeof process === 'undefined' || ! process . env ?. RNTL_SKIP_AUTO_CLEANUP ) {
@@ -11,7 +11,7 @@ if (typeof process === 'undefined' || !process.env?.RNTL_SKIP_AUTO_CLEANUP) {
11
11
if ( typeof afterEach === 'function' ) {
12
12
// eslint-disable-next-line no-undef
13
13
afterEach ( async ( ) => {
14
- await flushMicroTasks ( ) ;
14
+ await flushMicroTasksLegacy ( ) ;
15
15
cleanup ( ) ;
16
16
} ) ;
17
17
}
Original file line number Diff line number Diff line change 1
1
/* globals jest */
2
2
import act , { setReactActEnvironment , getIsReactActEnvironment } from './act' ;
3
3
import { getConfig } from './config' ;
4
- import { flushMicroTasks } from './flushMicroTasks' ;
4
+ import { flushMicroTasks , flushMicroTasksLegacy } from './flushMicroTasks' ;
5
5
import { ErrorWithStack , copyStackTrace } from './helpers/errors' ;
6
6
import {
7
7
setTimeout ,
@@ -206,7 +206,7 @@ export default async function waitFor<T>(
206
206
try {
207
207
const result = await waitForInternal ( expectation , optionsWithStackTrace ) ;
208
208
// Flush the microtask queue before restoring the `act` environment
209
- await flushMicroTasks ( ) ;
209
+ await flushMicroTasksLegacy ( ) ;
210
210
return result ;
211
211
} finally {
212
212
setReactActEnvironment ( previousActEnvironment ) ;
You can’t perform that action at this time.
0 commit comments