Skip to content

Commit

Permalink
Add missing check to unmocked Scheduler warning (#16261)
Browse files Browse the repository at this point in the history
The unmocked Scheduler warning doesn't actually check if Scheduler
is mocked.
  • Loading branch information
acdlite committed Jul 31, 2019
1 parent f939df4 commit 3756167
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,17 @@ it('should warn in sync mode', () => {
ReactDOM.render(<App />, document.createElement('div'));
}).toWarnDev([]);
});

it('does not warn if Scheduler is mocked', () => {
jest.resetModules();
jest.mock('scheduler', () => require('scheduler/unstable_mock'));
React = require('react');
ReactDOM = require('react-dom');
ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.warnAboutUnmockedScheduler = true;

// This should not warn
expect(() => {
ReactDOM.render(<App />, document.createElement('div'));
}).toWarnDev([]);
});
9 changes: 6 additions & 3 deletions packages/react-reconciler/src/ReactFiberWorkLoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2576,11 +2576,14 @@ let didWarnAboutUnmockedScheduler = false;

export function warnIfUnmockedScheduler(fiber: Fiber) {
if (__DEV__) {
if (didWarnAboutUnmockedScheduler === false) {
if (
didWarnAboutUnmockedScheduler === false &&
Scheduler.unstable_flushAllWithoutAsserting === undefined
) {
if (fiber.mode & BatchedMode || fiber.mode & ConcurrentMode) {
didWarnAboutUnmockedScheduler = true;
warningWithoutStack(
Scheduler.unstable_flushAllWithoutAsserting !== undefined,
false,
'In Concurrent or Sync modes, the "scheduler" module needs to be mocked ' +
'to guarantee consistent behaviour across tests and browsers. ' +
'For example, with jest: \n' +
Expand All @@ -2590,7 +2593,7 @@ export function warnIfUnmockedScheduler(fiber: Fiber) {
} else if (warnAboutUnmockedScheduler === true) {
didWarnAboutUnmockedScheduler = true;
warningWithoutStack(
null,
false,
'Starting from React v17, the "scheduler" module will need to be mocked ' +
'to guarantee consistent behaviour across tests and browsers. ' +
'For example, with jest: \n' +
Expand Down

0 comments on commit 3756167

Please sign in to comment.