1- import type { ElementType } from 'react' ;
21import type { ReactTestInstance , ReactTestRendererJSON } from 'react-test-renderer' ;
32import type { NewPlugin } from 'pretty-format' ;
43import prettyFormat , { plugins } from 'pretty-format' ;
@@ -37,7 +36,7 @@ export function formatElement(
3736 // This prop is needed persuade the prettyFormat that the element is
3837 // a ReactTestRendererJSON instance, so it is formatted as JSX.
3938 $$typeof : Symbol . for ( 'react.test.json' ) ,
40- type : formatElementType ( element . type ) ,
39+ type : ` ${ element . type } ` ,
4140 props : mapProps ? mapProps ( props ) : props ,
4241 children : childrenToDisplay ,
4342 } ,
@@ -52,30 +51,6 @@ export function formatElement(
5251 ) ;
5352}
5453
55- export function formatElementType ( type : ElementType ) : string {
56- if ( typeof type === 'function' ) {
57- return type . displayName ?? type . name ;
58- }
59-
60- if ( typeof type === 'object' && 'type' in type ) {
61- // @ts -expect-error: despite typing this can happen for class components, e.g. HOCs
62- const nestedType = formatElementType ( type . type ) ;
63- if ( nestedType ) {
64- return nestedType ;
65- }
66- }
67-
68- if ( typeof type === 'object' && 'render' in type ) {
69- // @ts -expect-error: despite typing this can happen for class components, e.g. HOCs
70- const nestedType = formatElementType ( type . render ) ;
71- if ( nestedType ) {
72- return nestedType ;
73- }
74- }
75-
76- return `${ type } ` ;
77- }
78-
7954export function formatElementList ( elements : ReactTestInstance [ ] , options ?: FormatElementOptions ) {
8055 if ( elements . length === 0 ) {
8156 return '(no elements)' ;
0 commit comments