@@ -16,8 +16,6 @@ var ReactDOM;
1616var ReactDOMServer ;
1717var ReactTestUtils ;
1818
19- var ReactDOMFeatureFlags = require ( 'ReactDOMFeatureFlags' ) ;
20-
2119describe ( 'ReactComponent' , ( ) => {
2220 function normalizeCodeLocInfo ( str ) {
2321 return str && str . replace ( / \( a t .+ ?: \d + \) / g, '(at **)' ) ;
@@ -299,21 +297,11 @@ describe('ReactComponent', () => {
299297 'outer componentDidMount' ,
300298 'start update' ,
301299 // Previous (equivalent) refs get cleared
302- ...( ReactDOMFeatureFlags . useFiber
303- ? [
304- // Fiber renders first, resets refs later
305- 'inner 1 render' ,
306- 'inner 2 render' ,
307- 'ref 1 got null' ,
308- 'ref 2 got null' ,
309- ]
310- : [
311- // Stack resets refs before rendering
312- 'ref 1 got null' ,
313- 'inner 1 render' ,
314- 'ref 2 got null' ,
315- 'inner 2 render' ,
316- ] ) ,
300+ // Fiber renders first, resets refs later
301+ 'inner 1 render' ,
302+ 'inner 2 render' ,
303+ 'ref 1 got null' ,
304+ 'ref 2 got null' ,
317305 'inner 1 componentDidUpdate' ,
318306 'ref 1 got instance 1' ,
319307 'inner 2 componentDidUpdate' ,
@@ -408,8 +396,7 @@ describe('ReactComponent', () => {
408396 'Objects are not valid as a React child (found: object with keys ' +
409397 '{x, y, z}). If you meant to render a collection of children, use ' +
410398 'an array instead.' +
411- // Fiber gives a slightly better stack with the nearest host components
412- ( ReactDOMFeatureFlags . useFiber ? '\n in div (at **)' : '' ) ,
399+ '\n in div (at **)' ,
413400 ) ;
414401 } ) ;
415402
@@ -436,8 +423,7 @@ describe('ReactComponent', () => {
436423 'Objects are not valid as a React child (found: object with keys ' +
437424 '{a, b, c}). If you meant to render a collection of children, use ' +
438425 'an array instead.\n' +
439- // Fiber gives a slightly better stack with the nearest host components
440- ( ReactDOMFeatureFlags . useFiber ? ' in div (at **)\n' : '' ) +
426+ ' in div (at **)\n' +
441427 ' in Foo (at **)' ,
442428 ) ;
443429 } ) ;
@@ -460,8 +446,7 @@ describe('ReactComponent', () => {
460446 'Objects are not valid as a React child (found: object with keys ' +
461447 '{x, y, z}). If you meant to render a collection of children, use ' +
462448 'an array instead.' +
463- // Fiber gives a slightly better stack with the nearest host components
464- ( ReactDOMFeatureFlags . useFiber ? '\n in div (at **)' : '' ) ,
449+ '\n in div (at **)' ,
465450 ) ;
466451 } ) ;
467452
@@ -488,79 +473,76 @@ describe('ReactComponent', () => {
488473 'Objects are not valid as a React child (found: object with keys ' +
489474 '{a, b, c}). If you meant to render a collection of children, use ' +
490475 'an array instead.\n' +
491- // Fiber gives a slightly better stack with the nearest host components
492- ( ReactDOMFeatureFlags . useFiber ? ' in div (at **)\n' : '' ) +
476+ ' in div (at **)\n' +
493477 ' in Foo (at **)' ,
494478 ) ;
495479 } ) ;
496480
497- if ( ReactDOMFeatureFlags . useFiber ) {
498- describe ( 'with new features' , ( ) => {
499- it ( 'warns on function as a return value from a function' , ( ) => {
500- function Foo ( ) {
501- return Foo ;
502- }
503- spyOn ( console , 'error' ) ;
504- var container = document . createElement ( 'div' ) ;
505- ReactDOM . render ( < Foo /> , container ) ;
506- expectDev ( console . error . calls . count ( ) ) . toBe ( 1 ) ;
507- expectDev ( normalizeCodeLocInfo ( console . error . calls . argsFor ( 0 ) [ 0 ] ) ) . toBe (
508- 'Warning: Functions are not valid as a React child. This may happen if ' +
509- 'you return a Component instead of <Component /> from render. ' +
510- 'Or maybe you meant to call this function rather than return it.\n' +
511- ' in Foo (at **)' ,
512- ) ;
513- } ) ;
481+ describe ( 'with new features' , ( ) => {
482+ it ( 'warns on function as a return value from a function' , ( ) => {
483+ function Foo ( ) {
484+ return Foo ;
485+ }
486+ spyOn ( console , 'error' ) ;
487+ var container = document . createElement ( 'div' ) ;
488+ ReactDOM . render ( < Foo /> , container ) ;
489+ expectDev ( console . error . calls . count ( ) ) . toBe ( 1 ) ;
490+ expectDev ( normalizeCodeLocInfo ( console . error . calls . argsFor ( 0 ) [ 0 ] ) ) . toBe (
491+ 'Warning: Functions are not valid as a React child. This may happen if ' +
492+ 'you return a Component instead of <Component /> from render. ' +
493+ 'Or maybe you meant to call this function rather than return it.\n' +
494+ ' in Foo (at **)' ,
495+ ) ;
496+ } ) ;
514497
515- it ( 'warns on function as a return value from a class' , ( ) => {
516- class Foo extends React . Component {
517- render ( ) {
518- return Foo ;
519- }
498+ it ( 'warns on function as a return value from a class' , ( ) => {
499+ class Foo extends React . Component {
500+ render ( ) {
501+ return Foo ;
520502 }
521- spyOn ( console , 'error' ) ;
522- var container = document . createElement ( 'div' ) ;
523- ReactDOM . render ( < Foo /> , container ) ;
524- expectDev ( console . error . calls . count ( ) ) . toBe ( 1 ) ;
525- expectDev ( normalizeCodeLocInfo ( console . error . calls . argsFor ( 0 ) [ 0 ] ) ) . toBe (
526- 'Warning: Functions are not valid as a React child. This may happen if ' +
527- 'you return a Component instead of <Component /> from render. ' +
528- 'Or maybe you meant to call this function rather than return it.\n' +
529- ' in Foo (at **)' ,
530- ) ;
531- } ) ;
503+ }
504+ spyOn ( console , 'error' ) ;
505+ var container = document . createElement ( 'div' ) ;
506+ ReactDOM . render ( < Foo /> , container ) ;
507+ expectDev ( console . error . calls . count ( ) ) . toBe ( 1 ) ;
508+ expectDev ( normalizeCodeLocInfo ( console . error . calls . argsFor ( 0 ) [ 0 ] ) ) . toBe (
509+ 'Warning: Functions are not valid as a React child. This may happen if ' +
510+ 'you return a Component instead of <Component /> from render. ' +
511+ 'Or maybe you meant to call this function rather than return it.\n' +
512+ ' in Foo (at **)' ,
513+ ) ;
514+ } ) ;
532515
533- it ( 'warns on function as a child to host component' , ( ) => {
534- function Foo ( ) {
535- return < div > < span > { Foo } </ span > </ div > ;
536- }
537- spyOn ( console , 'error' ) ;
538- var container = document . createElement ( 'div' ) ;
539- ReactDOM . render ( < Foo /> , container ) ;
540- expectDev ( console . error . calls . count ( ) ) . toBe ( 1 ) ;
541- expectDev ( normalizeCodeLocInfo ( console . error . calls . argsFor ( 0 ) [ 0 ] ) ) . toBe (
542- 'Warning: Functions are not valid as a React child. This may happen if ' +
543- 'you return a Component instead of <Component /> from render. ' +
544- 'Or maybe you meant to call this function rather than return it.\n' +
545- ' in span (at **)\n' +
546- ' in div (at **)\n' +
547- ' in Foo (at **)' ,
548- ) ;
549- } ) ;
516+ it ( 'warns on function as a child to host component' , ( ) => {
517+ function Foo ( ) {
518+ return < div > < span > { Foo } </ span > </ div > ;
519+ }
520+ spyOn ( console , 'error' ) ;
521+ var container = document . createElement ( 'div' ) ;
522+ ReactDOM . render ( < Foo /> , container ) ;
523+ expectDev ( console . error . calls . count ( ) ) . toBe ( 1 ) ;
524+ expectDev ( normalizeCodeLocInfo ( console . error . calls . argsFor ( 0 ) [ 0 ] ) ) . toBe (
525+ 'Warning: Functions are not valid as a React child. This may happen if ' +
526+ 'you return a Component instead of <Component /> from render. ' +
527+ 'Or maybe you meant to call this function rather than return it.\n' +
528+ ' in span (at **)\n' +
529+ ' in div (at **)\n' +
530+ ' in Foo (at **)' ,
531+ ) ;
532+ } ) ;
550533
551- it ( 'does not warn for function-as-a-child that gets resolved' , ( ) => {
552- function Bar ( props ) {
553- return props . children ( ) ;
554- }
555- function Foo ( ) {
556- return < Bar > { ( ) => 'Hello' } </ Bar > ;
557- }
558- spyOn ( console , 'error' ) ;
559- var container = document . createElement ( 'div' ) ;
560- ReactDOM . render ( < Foo /> , container ) ;
561- expect ( container . innerHTML ) . toBe ( 'Hello' ) ;
562- expectDev ( console . error . calls . count ( ) ) . toBe ( 0 ) ;
563- } ) ;
534+ it ( 'does not warn for function-as-a-child that gets resolved' , ( ) => {
535+ function Bar ( props ) {
536+ return props . children ( ) ;
537+ }
538+ function Foo ( ) {
539+ return < Bar > { ( ) => 'Hello' } </ Bar > ;
540+ }
541+ spyOn ( console , 'error' ) ;
542+ var container = document . createElement ( 'div' ) ;
543+ ReactDOM . render ( < Foo /> , container ) ;
544+ expect ( container . innerHTML ) . toBe ( 'Hello' ) ;
545+ expectDev ( console . error . calls . count ( ) ) . toBe ( 0 ) ;
564546 } ) ;
565- }
547+ } ) ;
566548} ) ;
0 commit comments