Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/__tests__/__snapshots__/render.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ exports[`debug 1`] = `
>
Second Text
</Text>
<Text>
0
</Text>
</View>"
`;

Expand Down Expand Up @@ -117,6 +120,9 @@ exports[`debug changing component: bananaFresh button message should now be "fre
>
Second Text
</Text>
<Text>
0
</Text>
</View>"
`;

Expand Down Expand Up @@ -162,6 +168,9 @@ exports[`debug: shallow 1`] = `
>
Second Text
</Text>
<Text>
0
</Text>
</View>"
`;

Expand Down Expand Up @@ -209,6 +218,9 @@ exports[`debug: shallow with message 1`] = `
>
Second Text
</Text>
<Text>
0
</Text>
</View>"
`;

Expand Down Expand Up @@ -271,6 +283,9 @@ exports[`debug: with message 1`] = `
>
Second Text
</Text>
<Text>
0
</Text>
</View>"
`;

Expand Down
7 changes: 6 additions & 1 deletion src/__tests__/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Banana extends React.Component<*, *> {
};

render() {
const test = 0;
return (
<View>
<Text>Is the banana fresh?</Text>
Expand All @@ -73,6 +74,7 @@ class Banana extends React.Component<*, *> {
</Button>
<Text testID="duplicateText">First Text</Text>
<Text testID="duplicateText">Second Text</Text>
<Text>{test}</Text>
</View>
);
}
Expand Down Expand Up @@ -122,7 +124,7 @@ test('getByName, queryByName', () => {

expect(bananaFresh.props.children).toBe('not fresh');
expect(() => getByName('InExistent')).toThrow('No instances found');
expect(() => getByName(Text)).toThrow('Expected 1 but found 5');
expect(() => getByName(Text)).toThrow('Expected 1 but found 6');

expect(queryByName('Button')).toBe(button);
expect(queryByName('InExistent')).toBeNull();
Expand Down Expand Up @@ -166,9 +168,12 @@ test('getByText, queryByText', () => {
expect(sameButton.props.children).toBe('not fresh');
expect(() => getByText('InExistent')).toThrow('No instances found');

const zeroText = getByText('0');

expect(queryByText(/change/i)).toBe(button);
expect(queryByText('InExistent')).toBeNull();
expect(() => queryByText(/fresh/)).toThrow('Expected 1 but found 3');
expect(queryByText('0')).toBe(zeroText);
});

test('getByText, queryByText with children as Array', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/getByAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const getNodeByText = (node, text) => {
if (isTextComponent) {
const textChildren = React.Children.map(
node.props.children,
// In some cases child might be undefined
child => (child ? child.toString() : '')
// In some cases child might be undefined or null
child => (child !== undefined && child !== null ? child.toString() : '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
child => (child !== undefined && child !== null ? child.toString() : '')
child => (child ?? child.toString() : '')

);
if (textChildren) {
const textToTest = textChildren.join('');
Expand Down