Skip to content

Commit 0b5fbb1

Browse files
committed
.
1 parent 6163f4b commit 0b5fbb1

File tree

1 file changed

+1
-26
lines changed

1 file changed

+1
-26
lines changed

src/helpers/format-element.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { ElementType } from 'react';
21
import type { ReactTestInstance, ReactTestRendererJSON } from 'react-test-renderer';
32
import type { NewPlugin } from 'pretty-format';
43
import 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-
7954
export function formatElementList(elements: ReactTestInstance[], options?: FormatElementOptions) {
8055
if (elements.length === 0) {
8156
return '(no elements)';

0 commit comments

Comments
 (0)