|
1 | 1 | import type { ReactTestInstance } from 'react-test-renderer'; |
2 | 2 | import { Text } from 'react-native'; |
3 | | -import { findAll } from '../helpers/findAll'; |
4 | | -import { matchTextContent } from '../helpers/matchers/matchTextContent'; |
5 | | -import { TextMatch, TextMatchOptions } from '../matches'; |
| 3 | +import { getConfig } from '../config'; |
6 | 4 | import { |
7 | 5 | getCompositeParentOfType, |
8 | 6 | isHostElementForType, |
9 | 7 | } from '../helpers/component-tree'; |
10 | | -import { getConfig } from '../config'; |
| 8 | +import { filterNodeByType } from '../helpers/filterNodeByType'; |
| 9 | +import { findAll } from '../helpers/findAll'; |
| 10 | +import { getHostComponentNames } from '../helpers/host-component-names'; |
| 11 | +import { matchTextContent } from '../helpers/matchers/matchTextContent'; |
| 12 | +import { TextMatch, TextMatchOptions } from '../matches'; |
11 | 13 | import { makeQueries } from './makeQueries'; |
12 | 14 | import type { |
13 | 15 | FindAllByQuery, |
@@ -39,18 +41,25 @@ const queryAllByText = ( |
39 | 41 |
|
40 | 42 | const results = findAll( |
41 | 43 | baseInstance, |
42 | | - (node) => matchTextContent(node, text, options), |
| 44 | + (node) => |
| 45 | + filterNodeByType(node, Text) && matchTextContent(node, text, options), |
43 | 46 | { ...options, matchDeepestOnly: true } |
44 | 47 | ); |
45 | 48 |
|
46 | 49 | return results; |
47 | 50 | } |
48 | 51 |
|
49 | 52 | // vNext version: returns host Text |
50 | | - return findAll(instance, (node) => matchTextContent(node, text, options), { |
51 | | - ...options, |
52 | | - matchDeepestOnly: true, |
53 | | - }); |
| 53 | + return findAll( |
| 54 | + instance, |
| 55 | + (node) => |
| 56 | + filterNodeByType(node, getHostComponentNames().text) && |
| 57 | + matchTextContent(node, text, options), |
| 58 | + { |
| 59 | + ...options, |
| 60 | + matchDeepestOnly: true, |
| 61 | + } |
| 62 | + ); |
54 | 63 | }; |
55 | 64 |
|
56 | 65 | const getMultipleError = (text: TextMatch) => |
|
0 commit comments