diff --git a/src/__tests__/__snapshots__/render.test.js.snap b/src/__tests__/__snapshots__/render.test.js.snap
index 42a9b4dc1..2fe4b1f33 100644
--- a/src/__tests__/__snapshots__/render.test.js.snap
+++ b/src/__tests__/__snapshots__/render.test.js.snap
@@ -57,6 +57,9 @@ exports[`debug 1`] = `
>
Second Text
+
+ 0
+
"
`;
@@ -117,6 +120,9 @@ exports[`debug changing component: bananaFresh button message should now be "fre
>
Second Text
+
+ 0
+
"
`;
@@ -162,6 +168,9 @@ exports[`debug: shallow 1`] = `
>
Second Text
+
+ 0
+
"
`;
@@ -209,6 +218,9 @@ exports[`debug: shallow with message 1`] = `
>
Second Text
+
+ 0
+
"
`;
@@ -271,6 +283,9 @@ exports[`debug: with message 1`] = `
>
Second Text
+
+ 0
+
"
`;
diff --git a/src/__tests__/render.test.js b/src/__tests__/render.test.js
index 3bfe58cef..c1e3312c4 100644
--- a/src/__tests__/render.test.js
+++ b/src/__tests__/render.test.js
@@ -52,6 +52,7 @@ class Banana extends React.Component<*, *> {
};
render() {
+ const test = 0;
return (
Is the banana fresh?
@@ -73,6 +74,7 @@ class Banana extends React.Component<*, *> {
First Text
Second Text
+ {test}
);
}
@@ -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();
@@ -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', () => {
diff --git a/src/helpers/getByAPI.js b/src/helpers/getByAPI.js
index 0bf99d16f..d352d0925 100644
--- a/src/helpers/getByAPI.js
+++ b/src/helpers/getByAPI.js
@@ -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() : '')
);
if (textChildren) {
const textToTest = textChildren.join('');