Skip to content

Commit 3756167

Browse files
authored
Add missing check to unmocked Scheduler warning (#16261)
The unmocked Scheduler warning doesn't actually check if Scheduler is mocked.
1 parent f939df4 commit 3756167

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

packages/react-dom/src/__tests__/ReactUnmockedSchedulerWarning-test.internal.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,17 @@ it('should warn in sync mode', () => {
4040
ReactDOM.render(<App />, document.createElement('div'));
4141
}).toWarnDev([]);
4242
});
43+
44+
it('does not warn if Scheduler is mocked', () => {
45+
jest.resetModules();
46+
jest.mock('scheduler', () => require('scheduler/unstable_mock'));
47+
React = require('react');
48+
ReactDOM = require('react-dom');
49+
ReactFeatureFlags = require('shared/ReactFeatureFlags');
50+
ReactFeatureFlags.warnAboutUnmockedScheduler = true;
51+
52+
// This should not warn
53+
expect(() => {
54+
ReactDOM.render(<App />, document.createElement('div'));
55+
}).toWarnDev([]);
56+
});

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,11 +2576,14 @@ let didWarnAboutUnmockedScheduler = false;
25762576

25772577
export function warnIfUnmockedScheduler(fiber: Fiber) {
25782578
if (__DEV__) {
2579-
if (didWarnAboutUnmockedScheduler === false) {
2579+
if (
2580+
didWarnAboutUnmockedScheduler === false &&
2581+
Scheduler.unstable_flushAllWithoutAsserting === undefined
2582+
) {
25802583
if (fiber.mode & BatchedMode || fiber.mode & ConcurrentMode) {
25812584
didWarnAboutUnmockedScheduler = true;
25822585
warningWithoutStack(
2583-
Scheduler.unstable_flushAllWithoutAsserting !== undefined,
2586+
false,
25842587
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
25852588
'to guarantee consistent behaviour across tests and browsers. ' +
25862589
'For example, with jest: \n' +
@@ -2590,7 +2593,7 @@ export function warnIfUnmockedScheduler(fiber: Fiber) {
25902593
} else if (warnAboutUnmockedScheduler === true) {
25912594
didWarnAboutUnmockedScheduler = true;
25922595
warningWithoutStack(
2593-
null,
2596+
false,
25942597
'Starting from React v17, the "scheduler" module will need to be mocked ' +
25952598
'to guarantee consistent behaviour across tests and browsers. ' +
25962599
'For example, with jest: \n' +

0 commit comments

Comments
 (0)