react-testing-library – Screen vs Render queries

The latest recommended option by the react-testing-library author Kent C. Dodds himself is to use screen.

The benefit of using screen is you no longer need to keep the render call destructure up-to-date as you add/remove the queries you need. You only need to type screen. and let your editor’s magic autocomplete take care of the rest.

The only exception to this is if you’re setting the container or baseElement which you probably should avoid doing (I honestly can’t think of a legitimate use case for those options anymore and they only exist for historical reasons at this point).

Source: https://kentcdodds.com/blog/common-mistakes-with-react-testing-library#not-using-screen

Leave a Comment