Skip to content

Ability to query children of given element #297

Closed
@mdjastrzebski

Description

@mdjastrzebski

Describe the Feature

In certain scenarios it is useful to restrict query to only a part of component tree.
Sample use cases:

  1. when displaying a FlatList of items we might want to find a certain item and query for some views inside it
  2. 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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions