forked from callstack/react-native-testing-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflush-micro-tasks.ts
30 lines (27 loc) · 953 Bytes
/
flush-micro-tasks.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { setImmediate } from './helpers/timers';
export function flushMicroTasks() {
return new Promise((resolve) => setImmediate(resolve));
}
/**
* @deprecated To be removed in the next major release.
*/
type Thenable<T> = { then: (callback: () => T) => unknown };
/**
* This legacy implementation of `flushMicroTasks` is used for compatibility with
* older versions of React Native (pre 0.71) which uses Promise polyfil.
*
* For users with older version of React Native there is a workaround of using our own
* Jest preset instead the `react-native` one, but requiring such change would be a
* breaking change for existing users.
*
* @deprecated To be removed in the next major release.
*/
export function flushMicroTasksLegacy(): Thenable<void> {
return {
// using "thenable" instead of a Promise, because otherwise it breaks when
// using "modern" fake timers
then(resolve) {
setImmediate(resolve);
},
};
}