File tree 1 file changed +19
-2
lines changed
1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change 3
3
// and the part that is not cannot easily have useful tests written
4
4
// anyway. So we're just going to ignore coverage for this file
5
5
/**
6
- * copied from React's enqueueTask.js
6
+ * copied and modified from React's enqueueTask.js
7
7
*/
8
8
9
+ function getIsUsingFakeTimers ( ) {
10
+ return (
11
+ typeof jest !== 'undefined' &&
12
+ typeof setTimeout !== 'undefined' &&
13
+ ( setTimeout . hasOwnProperty ( '_isMockFunction' ) ||
14
+ setTimeout . hasOwnProperty ( 'clock' ) )
15
+ )
16
+ }
17
+
9
18
let didWarnAboutMessageChannel = false
10
19
let enqueueTask
11
20
try {
43
52
export default function flushMicroTasks ( ) {
44
53
return {
45
54
then ( resolve ) {
46
- enqueueTask ( resolve )
55
+ if ( getIsUsingFakeTimers ( ) ) {
56
+ // without this, a test using fake timers would never get microtasks
57
+ // actually flushed. I spent several days on this... Really hard to
58
+ // reproduce the problem, so there's no test for it. But it works!
59
+ jest . advanceTimersByTime ( 0 )
60
+ resolve ( )
61
+ } else {
62
+ enqueueTask ( resolve )
63
+ }
47
64
} ,
48
65
}
49
66
}
You can’t perform that action at this time.
0 commit comments