mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Add missing check to unmocked Scheduler warning (#16261)
The unmocked Scheduler warning doesn't actually check if Scheduler is mocked.
This commit is contained in:
@@ -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([]);
|
||||
});
|
||||
|
||||
+6
-3
@@ -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' +
|
||||
@@ -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' +
|
||||
|
||||
Reference in New Issue
Block a user