Skip to content

Commit bcc52a5

Browse files
Mariia MarchenkovaMariia Marchenkova
Mariia Marchenkova
authored and
Mariia Marchenkova
committed
feat: query nested text nodes
1 parent ae3d4af commit bcc52a5

File tree

2 files changed

+33
-208
lines changed

2 files changed

+33
-208
lines changed

src/helpers/getByAPI.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,37 @@ const getNodeByText = (node, text) => {
3636
};
3737

3838
const getChildrenAsText = children => {
39-
return React.Children.map(children, child => {
39+
let textContent = [];
40+
41+
React.Children.map(children, child => {
4042
if (typeof child === 'string') {
41-
return child;
43+
return textContent.push(child);
4244
}
4345

4446
if (typeof child === 'number') {
45-
return child.toString();
47+
return textContent.push(child.toString());
4648
}
4749

48-
return '';
50+
if (child.props.children) {
51+
const { children } = child.props;
52+
53+
if (children instanceof Array) {
54+
children.forEach(node => {
55+
// eslint-disable-next-line
56+
const { Text } = require('react-native');
57+
if (filterNodeByType(node, Text)) {
58+
return textContent.push(node.props.children);
59+
}
60+
});
61+
} else {
62+
if (typeof children === 'string') {
63+
return textContent.push(children);
64+
}
65+
}
66+
}
4967
});
68+
69+
return textContent;
5070
};
5171

5272
const getTextInputNodeByPlaceholder = (node, placeholder) => {

0 commit comments

Comments
 (0)