@@ -498,11 +498,8 @@ describe('memo', () => {
498498 } ) ;
499499 } ) ;
500500
501- it ( 'should honor a displayName if set on the memo wrapper in warnings' , ( ) => {
502- const MemoComponent = React . memo ( function Component ( props ) {
503- return < div { ...props } /> ;
504- } ) ;
505- MemoComponent . displayName = 'Foo' ;
501+ it ( 'should fall back to showing something meaningful if no displayName or name are present' , ( ) => {
502+ const MemoComponent = React . memo ( props => < div { ...props } /> ) ;
506503 MemoComponent . propTypes = {
507504 required : PropTypes . string . isRequired ,
508505 } ;
@@ -511,19 +508,20 @@ describe('memo', () => {
511508 ReactNoop . render ( < MemoComponent optional = "foo" /> ) ,
512509 ) . toErrorDev (
513510 'Warning: Failed prop type: The prop `required` is marked as required in ' +
514- '`Foo`, but its value is `undefined`.\n' +
515- ' in Foo (at **)' ,
511+ '`Memo`, but its value is `undefined`.' ,
512+ // There's no component stack in this warning because the inner function is anonymous.
513+ // If we wanted to support this (for the Error frames / source location)
514+ // we could do this by updating ReactComponentStackFrame.
515+ { withoutStack : true } ,
516516 ) ;
517517 } ) ;
518518
519- it ( 'should honor a outter displayName when wrapped component and memo component set displayName at the same time. ' , ( ) => {
519+ it ( 'should honor a displayName if set on the inner component in warnings ' , ( ) => {
520520 function Component ( props ) {
521521 return < div { ...props } /> ;
522522 }
523- Component . displayName = 'Foo' ;
524-
523+ Component . displayName = 'Inner' ;
525524 const MemoComponent = React . memo ( Component ) ;
526- MemoComponent . displayName = 'Bar' ;
527525 MemoComponent . propTypes = {
528526 required : PropTypes . string . isRequired ,
529527 } ;
@@ -532,21 +530,37 @@ describe('memo', () => {
532530 ReactNoop . render ( < MemoComponent optional = "foo" /> ) ,
533531 ) . toErrorDev (
534532 'Warning: Failed prop type: The prop `required` is marked as required in ' +
535- '`Bar`, but its value is `undefined`.\n' +
536- ' in Bar (at **)' ,
533+ '`Inner`, but its value is `undefined`.\n' +
534+ ' in Inner (at **)' ,
535+ ) ;
536+ } ) ;
537+
538+ it ( 'should honor a displayName if set on the memo wrapper in warnings' , ( ) => {
539+ const MemoComponent = React . memo ( function Component ( props ) {
540+ return < div { ...props } /> ;
541+ } ) ;
542+ MemoComponent . displayName = 'Outer' ;
543+ MemoComponent . propTypes = {
544+ required : PropTypes . string . isRequired ,
545+ } ;
546+
547+ expect ( ( ) =>
548+ ReactNoop . render ( < MemoComponent optional = "foo" /> ) ,
549+ ) . toErrorDev (
550+ 'Warning: Failed prop type: The prop `required` is marked as required in ' +
551+ '`Outer`, but its value is `undefined`.\n' +
552+ ' in Component (at **)' ,
537553 ) ;
538554 } ) ;
539555
540- it ( 'can set react memo component displayName multiple times ' , ( ) => {
556+ it ( 'should honor a outer displayName when wrapped component and memo component set displayName at the same time. ' , ( ) => {
541557 function Component ( props ) {
542558 return < div { ...props } /> ;
543559 }
544- Component . displayName = 'Foo ' ;
560+ Component . displayName = 'Inner ' ;
545561
546562 const MemoComponent = React . memo ( Component ) ;
547- MemoComponent . displayName = 'MemoComp01' ;
548- MemoComponent . displayName = 'MemoComp02' ;
549- MemoComponent . displayName = 'MemoComp03' ;
563+ MemoComponent . displayName = 'Outer' ;
550564 MemoComponent . propTypes = {
551565 required : PropTypes . string . isRequired ,
552566 } ;
@@ -555,8 +569,8 @@ describe('memo', () => {
555569 ReactNoop . render ( < MemoComponent optional = "foo" /> ) ,
556570 ) . toErrorDev (
557571 'Warning: Failed prop type: The prop `required` is marked as required in ' +
558- '`MemoComp03 `, but its value is `undefined`.\n' +
559- ' in MemoComp03 (at **)' ,
572+ '`Outer `, but its value is `undefined`.\n' +
573+ ' in Inner (at **)' ,
560574 ) ;
561575 } ) ;
562576 }
0 commit comments