Skip to content

Commit

Permalink
fix: improve element formatting (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjastrzebski authored Oct 21, 2022
1 parent 1b65ce3 commit b36fc6c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
26 changes: 11 additions & 15 deletions src/__tests__/__snapshots__/to-be-visible.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,21 @@ exports[`.toBeVisible throws an error when expectation is not matched 1`] = `
"expect(element).not.toBeVisible()
Received element is visible:
Object {
"props": Object {
"children": undefined,
"testID": "test",
},
}"
<View
testID="test"
/>"
`;

exports[`.toBeVisible throws an error when expectation is not matched 2`] = `
"expect(element).toBeVisible()
Received element is not visible:
Object {
"props": Object {
"children": undefined,
"style": Object {
"opacity": 0,
},
"testID": "test",
},
}"
<View
style={
{
"opacity": 0,
}
}
testID="test"
/>"
`;
26 changes: 18 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,24 @@ function printElement(element: ReactTestInstance | null) {
return 'null';
}

return ` ${prettyFormat(
{ props: element.props },
{
plugins: [ReactTestComponent, ReactElement],
printFunctionName: false,
highlight: true,
},
)}`;
return redent(
prettyFormat(
{
// This prop is needed persuade the prettyFormat that the element is
// a ReactTestRendererJSON instance, so it is formatted as JSX.
$$typeof: Symbol.for('react.test.json'),
type: element.type,
props: element.props,
},
{
plugins: [ReactTestComponent, ReactElement],
printFunctionName: false,
printBasicPrototype: false,
highlight: true,
},
),
2,
);
}

function display(value: unknown) {
Expand Down

0 comments on commit b36fc6c

Please sign in to comment.