Skip to content

Commit ccad804

Browse files
authored
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
1 parent 1d5e15b commit ccad804

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/helpers/getByAPI.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ const getNodeByText = (node, text) => {
2020
const isTextComponent =
2121
filterNodeByType(node, Text) || filterNodeByType(node, TextInput);
2222
if (isTextComponent) {
23-
const textChildren = React.Children.map(node.props.children, child =>
24-
child.toString()
23+
const textChildren = React.Children.map(
24+
node.props.children,
25+
// In some cases child might be undefined
26+
child => (child ? child.toString() : '')
2527
);
2628
if (textChildren) {
2729
const textToTest = textChildren.join('');

0 commit comments

Comments
 (0)