Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The docs advice against using container for querying rendered elements in React Testing Library #3544

Open
xTanzu opened this issue Mar 29, 2024 · 0 comments
Labels

Comments

@xTanzu
Copy link

xTanzu commented Mar 29, 2024

I found this in the documentation:

🚨 If you find yourself using container to query for rendered elements then you should reconsider! The other queries are designed to be more resilient to changes that will be made to the component you're testing. Avoid using container to query for elements!

Should the material not push this behaviour? Parts of the material use this quite actively, like this:

let container = render(
      <Togglable buttonLabel="show...">
        ...
      </Togglable>
    ).container
const div = container.querySelector('.togglableContent')

Should we use the library specific queries overviewed in https://testing-library.com/docs/queries/about#types-of-queries

@vejol vejol added the part 5 label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants