(
instance: TestInstance | null,
{ compact, highlight = true, mapProps = defaultMapProps }: FormatElementOptions = {},
)
| 22 | * @param instance Instance to format. |
| 23 | */ |
| 24 | export function formatElement( |
| 25 | instance: TestInstance | null, |
| 26 | { compact, highlight = true, mapProps = defaultMapProps }: FormatElementOptions = {}, |
| 27 | ) { |
| 28 | if (instance == null) { |
| 29 | return '(null)'; |
| 30 | } |
| 31 | |
| 32 | const { children, ...props } = instance.props; |
| 33 | const childrenToDisplay = typeof children === 'string' ? [children] : undefined; |
| 34 | |
| 35 | return prettyFormat( |
| 36 | { |
| 37 | // This prop is needed persuade the prettyFormat that the element is |
| 38 | // a JsonNode instance, so it is formatted as JSX. |
| 39 | $$typeof: Symbol.for('react.test.json'), |
| 40 | type: `${instance.type}`, |
| 41 | props: mapProps ? mapProps(props) : props, |
| 42 | children: childrenToDisplay, |
| 43 | }, |
| 44 | // See: https://www.npmjs.com/package/pretty-format#usage-with-options |
| 45 | { |
| 46 | plugins: [plugins.ReactTestComponent, plugins.ReactElement], |
| 47 | printFunctionName: false, |
| 48 | printBasicPrototype: false, |
| 49 | highlight: highlight, |
| 50 | min: compact, |
| 51 | }, |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | export function formatElementList(instances: TestInstance[], options?: FormatElementOptions) { |
| 56 | if (instances.length === 0) { |
no outgoing calls
no test coverage detected
searching dependent graphs…