@@ -799,45 +799,48 @@ describe('ReactErrorBoundaries', () => {
799799 expect ( container . firstChild . textContent ) . toBe ( 'Caught an error: Hello.' ) ;
800800 } ) ;
801801
802- // @gate !disableModulePatternComponents
803- // @gate !disableLegacyContext
804- it ( 'renders an error state if module-style context provider throws in componentWillMount' , ( ) => {
805- function BrokenComponentWillMountWithContext ( ) {
806- return {
807- getChildContext ( ) {
808- return { foo : 42 } ;
809- } ,
810- render ( ) {
811- return < div > { this . props . children } </ div > ;
812- } ,
813- UNSAFE_componentWillMount ( ) {
814- throw new Error ( 'Hello' ) ;
815- } ,
802+ if (
803+ ! require ( 'shared/ReactFeatureFlags' ) . disableModulePatternComponents &&
804+ ! require ( 'shared/ReactFeatureFlags' ) . disableLegacyContext
805+ ) {
806+ it ( 'renders an error state if module-style context provider throws in componentWillMount' , ( ) => {
807+ function BrokenComponentWillMountWithContext ( ) {
808+ return {
809+ getChildContext ( ) {
810+ return { foo : 42 } ;
811+ } ,
812+ render ( ) {
813+ return < div > { this . props . children } </ div > ;
814+ } ,
815+ UNSAFE_componentWillMount ( ) {
816+ throw new Error ( 'Hello' ) ;
817+ } ,
818+ } ;
819+ }
820+ BrokenComponentWillMountWithContext . childContextTypes = {
821+ foo : PropTypes . number ,
816822 } ;
817- }
818- BrokenComponentWillMountWithContext . childContextTypes = {
819- foo : PropTypes . number ,
820- } ;
821823
822- const container = document . createElement ( 'div' ) ;
823- expect ( ( ) =>
824- ReactDOM . render (
825- < ErrorBoundary >
826- < BrokenComponentWillMountWithContext />
827- </ ErrorBoundary > ,
828- container ,
829- ) ,
830- ) . toErrorDev (
831- 'Warning: The <BrokenComponentWillMountWithContext /> component appears to be a function component that ' +
832- 'returns a class instance. ' +
833- 'Change BrokenComponentWillMountWithContext to a class that extends React.Component instead. ' +
834- "If you can't use a class try assigning the prototype on the function as a workaround. " +
835- '`BrokenComponentWillMountWithContext.prototype = React.Component.prototype`. ' +
836- "Don't use an arrow function since it cannot be called with `new` by React." ,
837- ) ;
824+ const container = document . createElement ( 'div' ) ;
825+ expect ( ( ) =>
826+ ReactDOM . render (
827+ < ErrorBoundary >
828+ < BrokenComponentWillMountWithContext />
829+ </ ErrorBoundary > ,
830+ container ,
831+ ) ,
832+ ) . toErrorDev (
833+ 'Warning: The <BrokenComponentWillMountWithContext /> component appears to be a function component that ' +
834+ 'returns a class instance. ' +
835+ 'Change BrokenComponentWillMountWithContext to a class that extends React.Component instead. ' +
836+ "If you can't use a class try assigning the prototype on the function as a workaround. " +
837+ '`BrokenComponentWillMountWithContext.prototype = React.Component.prototype`. ' +
838+ "Don't use an arrow function since it cannot be called with `new` by React." ,
839+ ) ;
838840
839- expect ( container . firstChild . textContent ) . toBe ( 'Caught an error: Hello.' ) ;
840- } ) ;
841+ expect ( container . firstChild . textContent ) . toBe ( 'Caught an error: Hello.' ) ;
842+ } ) ;
843+ }
841844
842845 it ( 'mounts the error message if mounting fails' , ( ) => {
843846 function renderError ( error ) {
0 commit comments