@@ -722,14 +722,41 @@ test('supports forwardRef with a child', () => {
722
722
) . toEqual ( '<ForwardRef(Cat)>\n mouse\n</ForwardRef(Cat)>' ) ;
723
723
} ) ;
724
724
725
- test ( 'supports memo with a child' , ( ) => {
726
- function Dog ( props : any ) {
727
- return React . createElement ( 'div' , props , props . children ) ;
728
- }
725
+ describe ( 'React.memo' , ( ) => {
726
+ describe ( 'without displayName' , ( ) => {
727
+ test ( 'renders the component name' , ( ) => {
728
+ function Dog ( props : any ) {
729
+ return React . createElement ( 'div' , props , props . children ) ;
730
+ }
731
+
732
+ expect (
733
+ formatElement ( React . createElement ( React . memo ( Dog ) , null , 'cat' ) ) ,
734
+ ) . toEqual ( '<Memo(Dog)>\n cat\n</Memo(Dog)>' ) ;
735
+ } ) ;
736
+ } ) ;
729
737
730
- expect (
731
- formatElement ( React . createElement ( React . memo ( Dog ) , null , 'cat' ) ) ,
732
- ) . toEqual ( '<Memo(Dog)>\n cat\n</Memo(Dog)>' ) ;
738
+ describe ( 'with displayName' , ( ) => {
739
+ test ( 'renders the displayName of component before memoizing' , ( ) => {
740
+ const Foo = ( ) => React . createElement ( 'div' ) ;
741
+ Foo . displayName = 'DisplayNameBeforeMemoizing(Foo)' ;
742
+ const MemoFoo = React . memo ( Foo ) ;
743
+
744
+ expect ( formatElement ( React . createElement ( MemoFoo , null , 'cat' ) ) ) . toEqual (
745
+ '<Memo(DisplayNameBeforeMemoizing(Foo))>\n cat\n</Memo(DisplayNameBeforeMemoizing(Foo))>' ,
746
+ ) ;
747
+ } ) ;
748
+
749
+ test ( 'renders the displayName of memoized component' , ( ) => {
750
+ const Foo = ( ) => React . createElement ( 'div' ) ;
751
+ Foo . displayName = 'DisplayNameThatWillBeIgnored(Foo)' ;
752
+ const MemoFoo = React . memo ( Foo ) ;
753
+ MemoFoo . displayName = 'DisplayNameForMemoized(Foo)' ;
754
+
755
+ expect ( formatElement ( React . createElement ( MemoFoo , null , 'cat' ) ) ) . toEqual (
756
+ '<Memo(DisplayNameForMemoized(Foo))>\n cat\n</Memo(DisplayNameForMemoized(Foo))>' ,
757
+ ) ;
758
+ } ) ;
759
+ } ) ;
733
760
} ) ;
734
761
735
762
test ( 'supports context Provider with a child' , ( ) => {
0 commit comments