Why do DOM queries need to be destructured from the render function when using React Testing Library

Viewed 51

Trying to learn how to test Redux with Jest/RTL, and I'm wondering why you would destructure DOM queries from the render method rather than just importing screen and calling them that way? The RTL docs say this about the render method:

The most important feature of render is that the queries from DOM Testing Library are automatically returned with their first argument bound to the baseElement, which defaults to document.body

Are these just two different ways to accomplish the same thing? I think I'm confused as to how all of this is actually interacting with the DOM. Any insight would be great, thank you!

0 Answers
Related