@@ -13,11 +13,14 @@ const React = require('react');
1313const ReactDOM = require ( 'react-dom' ) ;
1414const PropTypes = require ( 'prop-types' ) ;
1515let act ;
16+ let assertConsoleErrorDev ;
1617describe ( 'ReactDOMLegacyFiber' , ( ) => {
1718 let container ;
1819
1920 beforeEach ( ( ) => {
2021 act = require ( 'internal-test-utils' ) . act ;
22+ assertConsoleErrorDev =
23+ require ( 'internal-test-utils' ) . assertConsoleErrorDev ;
2124 container = document . createElement ( 'div' ) ;
2225 document . body . appendChild ( container ) ;
2326 } ) ;
@@ -786,9 +789,8 @@ describe('ReactDOMLegacyFiber', () => {
786789 }
787790 }
788791
789- expect ( ( ) => {
790- ReactDOM . render ( < Parent /> , container ) ;
791- } ) . toErrorDev ( [
792+ ReactDOM . render ( < Parent /> , container ) ;
793+ assertConsoleErrorDev ( [
792794 'Parent uses the legacy childContextTypes API which will soon be removed. Use React.createContext() instead.' ,
793795 'Component uses the legacy contextTypes API which will soon be removed. Use React.createContext() with static contextType instead.' ,
794796 ] ) ;
@@ -834,10 +836,8 @@ describe('ReactDOMLegacyFiber', () => {
834836 }
835837 }
836838
837- let instance ;
838- expect ( ( ) => {
839- instance = ReactDOM . render ( < Parent /> , container ) ;
840- } ) . toErrorDev ( [
839+ const instance = ReactDOM . render ( < Parent /> , container ) ;
840+ assertConsoleErrorDev ( [
841841 'Parent uses the legacy childContextTypes API which will soon be removed. Use React.createContext() instead.' ,
842842 'Component uses the legacy contextTypes API which will soon be removed. Use React.createContext() with static contextType instead.' ,
843843 ] ) ;
@@ -882,9 +882,8 @@ describe('ReactDOMLegacyFiber', () => {
882882 }
883883 }
884884
885- expect ( ( ) => {
886- ReactDOM . render ( < Parent bar = "initial" /> , container ) ;
887- } ) . toErrorDev ( [
885+ ReactDOM . render ( < Parent bar = "initial" /> , container ) ;
886+ assertConsoleErrorDev ( [
888887 'Parent uses the legacy childContextTypes API which will soon be removed. Use React.createContext() instead.' ,
889888 'Component uses the legacy contextTypes API which will soon be removed. Use React.createContext() with static contextType instead.' ,
890889 ] ) ;
@@ -1117,11 +1116,12 @@ describe('ReactDOMLegacyFiber', () => {
11171116 return < div onClick = "woops" /> ;
11181117 }
11191118 }
1120- expect ( ( ) => ReactDOM . render ( < Example /> , container ) ) . toErrorDev (
1119+ ReactDOM . render ( < Example /> , container ) ;
1120+ assertConsoleErrorDev ( [
11211121 'Expected `onClick` listener to be a function, instead got a value of `string` type.\n' +
11221122 ' in div (at **)\n' +
11231123 ' in Example (at **)' ,
1124- ) ;
1124+ ] ) ;
11251125 } ) ;
11261126
11271127 // @gate !disableLegacyMode
@@ -1131,13 +1131,14 @@ describe('ReactDOMLegacyFiber', () => {
11311131 return < div onClick = { false } /> ;
11321132 }
11331133 }
1134- expect ( ( ) => ReactDOM . render ( < Example /> , container ) ) . toErrorDev (
1134+ ReactDOM . render ( < Example /> , container ) ;
1135+ assertConsoleErrorDev ( [
11351136 'Expected `onClick` listener to be a function, instead got `false`.\n\n' +
11361137 'If you used to conditionally omit it with onClick={condition && value}, ' +
11371138 'pass onClick={condition ? value : undefined} instead.\n' +
11381139 ' in div (at **)\n' +
11391140 ' in Example (at **)' ,
1140- ) ;
1141+ ] ) ;
11411142 } ) ;
11421143
11431144 // @gate !disableLegacyMode
@@ -1270,17 +1271,18 @@ describe('ReactDOMLegacyFiber', () => {
12701271 container . innerHTML = '<div>MEOW.</div>' ;
12711272
12721273 await expect ( async ( ) => {
1273- await expect ( async ( ) => {
1274- await act ( ( ) => {
1275- ReactDOM . render ( < div key = "2" > baz</ div > , container ) ;
1276- } ) ;
1277- } ) . rejects . toThrow ( 'The node to be removed is not a child of this node.' ) ;
1278- } ) . toErrorDev (
1279- '' +
1280- 'It looks like the React-rendered content of this container was ' +
1281- 'removed without using React. This is not supported and will ' +
1282- 'cause errors. Instead, call ReactDOM.unmountComponentAtNode ' +
1283- 'to empty a container.' ,
1274+ await act ( ( ) => {
1275+ ReactDOM . render ( < div key = "2" > baz</ div > , container ) ;
1276+ } ) ;
1277+ } ) . rejects . toThrow ( 'The node to be removed is not a child of this node.' ) ;
1278+ assertConsoleErrorDev (
1279+ [
1280+ '' +
1281+ 'It looks like the React-rendered content of this container was ' +
1282+ 'removed without using React. This is not supported and will ' +
1283+ 'cause errors. Instead, call ReactDOM.unmountComponentAtNode ' +
1284+ 'to empty a container.' ,
1285+ ] ,
12841286 { withoutStack : true } ,
12851287 ) ;
12861288 } ) ;
@@ -1293,12 +1295,15 @@ describe('ReactDOMLegacyFiber', () => {
12931295 expect ( container . innerHTML ) . toBe ( '<div>bar</div>' ) ;
12941296 // then we mess with the DOM before an update
12951297 container . innerHTML = '<div>MEOW.</div>' ;
1296- expect ( ( ) => ReactDOM . render ( < div > baz</ div > , container ) ) . toErrorDev (
1297- '' +
1298- 'It looks like the React-rendered content of this container was ' +
1299- 'removed without using React. This is not supported and will ' +
1300- 'cause errors. Instead, call ReactDOM.unmountComponentAtNode ' +
1301- 'to empty a container.' ,
1298+ ReactDOM . render ( < div > baz</ div > , container ) ;
1299+ assertConsoleErrorDev (
1300+ [
1301+ '' +
1302+ 'It looks like the React-rendered content of this container was ' +
1303+ 'removed without using React. This is not supported and will ' +
1304+ 'cause errors. Instead, call ReactDOM.unmountComponentAtNode ' +
1305+ 'to empty a container.' ,
1306+ ] ,
13021307 { withoutStack : true } ,
13031308 ) ;
13041309 } ) ;
@@ -1311,12 +1316,15 @@ describe('ReactDOMLegacyFiber', () => {
13111316 expect ( container . innerHTML ) . toBe ( '<div>bar</div>' ) ;
13121317 // then we mess with the DOM before an update
13131318 container . innerHTML = '' ;
1314- expect ( ( ) => ReactDOM . render ( < div > baz</ div > , container ) ) . toErrorDev (
1315- '' +
1316- 'It looks like the React-rendered content of this container was ' +
1317- 'removed without using React. This is not supported and will ' +
1318- 'cause errors. Instead, call ReactDOM.unmountComponentAtNode ' +
1319- 'to empty a container.' ,
1319+ ReactDOM . render ( < div > baz</ div > , container ) ;
1320+ assertConsoleErrorDev (
1321+ [
1322+ '' +
1323+ 'It looks like the React-rendered content of this container was ' +
1324+ 'removed without using React. This is not supported and will ' +
1325+ 'cause errors. Instead, call ReactDOM.unmountComponentAtNode ' +
1326+ 'to empty a container.' ,
1327+ ] ,
13201328 { withoutStack : true } ,
13211329 ) ;
13221330 } ) ;
0 commit comments