Closed
Description
Describe the Feature
In certain scenarios it is useful to restrict query to only a part of component tree.
Sample use cases:
- when displaying a
FlatList
of items we might want to find a certain item and query for some views inside it - when rendering multi-screen integration test using react-navigation and navigating from list screen to details screen. The global query still returns elements from hidden master screen. Forcing test code to use getAllBy* with arbitrary indices instread of getBy* queries.
Possible Implementations
DOM/React Testing Library provides within
/getQueriesForElement
for such use case.
const boundQueries = within(getByA11yHint('Some Item'));
expect(boundQueries.getByText('Some text')).toBeTruthy();
Alternative would be to provide query functions accepting container element as one of their parameters e.g. getByText(container, text)
as in DOM Testing Library.
Related Issues
Not found.