fullstack-hy2020 / fullstack-hy2020.github.io

Home Page:https://fullstack-hy2020.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

xTanzu opened this issue · comments

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