From ccad8044eaad9505f6efb7ce28055a2c38befacd Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Tue, 19 Mar 2019 19:47:26 +0100 Subject: [PATCH] fix: check for undefined/null children (#136) ### Summary Check for undefined/null values, in `getByText` nodes. Fixes #135 ### Test plan Passing tests on repro repository https://github.com/wKovacs64/rntl-161-repro. Have no idea how to create a unit test, to test this behavior. cc @thymikee @wKovacs64 --- src/helpers/getByAPI.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/helpers/getByAPI.js b/src/helpers/getByAPI.js index 91b131a0..28685ff2 100644 --- a/src/helpers/getByAPI.js +++ b/src/helpers/getByAPI.js @@ -20,8 +20,10 @@ 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, + // In some cases child might be undefined + child => (child ? child.toString() : '') ); if (textChildren) { const textToTest = textChildren.join('');