From e9479615a1ab04b3d26821aac5a8a2d05bc457aa Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Tue, 19 Mar 2019 17:12:02 +0100 Subject: [PATCH 1/2] Check for undefined/null children --- src/helpers/getByAPI.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/helpers/getByAPI.js b/src/helpers/getByAPI.js index 91b131a08..0bb9c14df 100644 --- a/src/helpers/getByAPI.js +++ b/src/helpers/getByAPI.js @@ -20,8 +20,9 @@ const getNodeByText = (node, text) => { const isTextComponent = filterNodeByType(node, Text) || filterNodeByType(node, TextInput); if (isTextComponent) { - const textChildren = React.Children.map(node.props.children, child => - child.toString() + const textChildren = React.Children.map( + node.props.children, + child => (child ? child.toString() : '') ); if (textChildren) { const textToTest = textChildren.join(''); From aac7c79d36198d8f156e9ba14e486214f4ed6828 Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Tue, 19 Mar 2019 17:19:18 +0100 Subject: [PATCH 2/2] Add explanation comment --- src/helpers/getByAPI.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/helpers/getByAPI.js b/src/helpers/getByAPI.js index 0bb9c14df..28685ff29 100644 --- a/src/helpers/getByAPI.js +++ b/src/helpers/getByAPI.js @@ -22,6 +22,7 @@ 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() : '') ); if (textChildren) {