mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
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:
@@ -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('');
|
||||
|
||||
Reference in New Issue
Block a user