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
This commit is contained in:
Kacper Wiszczuk
2019-03-19 19:47:26 +01:00
committed by GitHub
parent 1d5e15b230
commit ccad8044ea
+4 -2
View File
@@ -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('');