MCPcopy Index your code
hub / github.com/callstack/react-native-testing-library / formatElement

Function formatElement

src/helpers/format-element.ts:24–53  ·  view source on GitHub ↗
(
  instance: TestInstance | null,
  { compact, highlight = true, mapProps = defaultMapProps }: FormatElementOptions = {},
)

Source from the content-addressed store, hash-verified

22 * @param instance Instance to format.
23 */
24export 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
55export function formatElementList(instances: TestInstance[], options?: FormatElementOptions) {
56 if (instances.length === 0) {

Callers 13

toBeVisibleFunction · 0.90
toBePartiallyCheckedFunction · 0.90
toBeBusyFunction · 0.90
toContainElementFunction · 0.90
toBeSelectedFunction · 0.90
toBeDisabledFunction · 0.90
toBeEnabledFunction · 0.90
errorFoundFunction · 0.90
toBeExpandedFunction · 0.90
toBeCollapsedFunction · 0.90
toBeCheckedFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…