Add missing check to unmocked Scheduler warning (#16261)
The unmocked Scheduler warning doesn't actually check if Scheduler is mocked.
Andrew Clark committed
Jul 30, 2019 at 20:11 UTC
375616788510d65b0d523fb1b331aefbd737d03d
2 files changed
+20
-3
packages/react-dom/src/__tests__/ReactUnmockedSchedulerWarning-test.internal.js
+14
@@ -40,3 +40,17 @@ it('should warn in sync mode', () => {
40
ReactDOM.render(<App />, document.createElement('div'));
41
}).toWarnDev([]);
42
});
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
+6
-3
@@ -2576,11 +2576,14 @@ let didWarnAboutUnmockedScheduler = false;
2576
2577
export function warnIfUnmockedScheduler(fiber: Fiber) {
2578
if (__DEV__) {
2579
- if (didWarnAboutUnmockedScheduler === false) {
2579
+ if (
2580
+ didWarnAboutUnmockedScheduler === false &&
2581
+ Scheduler.unstable_flushAllWithoutAsserting === undefined
2582
+ ) {
2583
if (fiber.mode & BatchedMode || fiber.mode & ConcurrentMode) {
2584
didWarnAboutUnmockedScheduler = true;
2585
warningWithoutStack(
2583
- Scheduler.unstable_flushAllWithoutAsserting !== undefined,
2586
+ false,
2587
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
2588
'to guarantee consistent behaviour across tests and browsers. ' +
2589
'For example, with jest: \n' +
@@ -2590,7 +2593,7 @@ export function warnIfUnmockedScheduler(fiber: Fiber) {
2593
} else if (warnAboutUnmockedScheduler === true) {
2594
didWarnAboutUnmockedScheduler = true;
2595
warningWithoutStack(
2593
- null,
2596
+ false,
2597
'Starting from React v17, the "scheduler" module will need to be mocked ' +
2598
'to guarantee consistent behaviour across tests and browsers. ' +
2599
'For example, with jest: \n' +