-
Notifications
You must be signed in to change notification settings - Fork 277
Closed
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Description
Describe the Feature
We currently use ReactTestInstance.findAll
method in order to traverse element tree. This is a basic tree walking algorithm that starts at the root and traverses recursively to the children.
There is one major issue with the current method: for query predicates that inspect all descendants (e.g. concat all string content) there is no easy way to find only the deepest element matching given predicate.
<Text testID="outer">
<Text testID="inner">
Hello.
</Text>
</Text>
When using a predict that will concat all nested string contents, then both outer and inner text will be matched.
Possible Implementations
This should be a function, with similar signature:
function findAll(element: ReactTestInstance, predicate: (element: ReactTestInstance) => boolean, options: FindAllOptions)
- it should work by traversing tree top-down from root (as current algorithm)
- but it should be inspecting the elements on its way back, so that the deepest element is matched first
- having information about deeper element having been matched inside given branch it would prevent it's ancestor elements also getting match
- this should be an optional behavior controlled by option passed inside
options
argument. Proposed initial option name:deepestOnly
(defaultfalse
) - it might be worth considering adding some additional argument to
predicate
callback to facilitate this
Applications
- This would be an internal API used by queries.
- It could allow us to improve some existing non-trivial queries, e.g.
*ByText
or*ByRole
withname
option
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed