Skip to content

Commit 6d56815

Browse files
committed
chore(flushMicroTasks): Use the mocked scheduler when available and mock the scheduler in our setup-env.
1 parent 9e5cf59 commit 6d56815

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/flush-microtasks.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ try {
5555
'if you encounter this warning.',
5656
)
5757
}
58-
5958
}
6059
}
6160

62-
const isModernScheduleCallbackSupported = Scheduler && satisfies(React.version, '>16.8.6', {
63-
includePrerelease: true,
64-
})
61+
const isModernScheduleCallbackSupported =
62+
Scheduler &&
63+
satisfies(React.version, '>16.8.6', {
64+
includePrerelease: true,
65+
})
6566

6667
function scheduleCallback(cb) {
6768
const NormalPriority = Scheduler
@@ -86,6 +87,9 @@ export default function flushMicroTasks() {
8687
// reproduce the problem, so there's no test for it. But it works!
8788
jest.advanceTimersByTime(0)
8889
resolve()
90+
} else if (Scheduler && Scheduler.unstable_flushAll) {
91+
Scheduler.unstable_flushAll()
92+
enqueueTask(resolve)
8993
} else {
9094
scheduleCallback(() => enqueueTask(resolve))
9195
}

tests/setup-env.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
import '@testing-library/jest-dom/extend-expect'
2+
jest.mock('scheduler', () => jest.requireActual('scheduler/unstable_mock'))

0 commit comments

Comments
 (0)