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

When to use screen object or component returned by renderPage #134

Closed
christianacca opened this issue Aug 21, 2020 · 3 comments
Closed

When to use screen object or component returned by renderPage #134

christianacca opened this issue Aug 21, 2020 · 3 comments

Comments

@christianacca
Copy link

christianacca commented Aug 21, 2020

Prior to version 10 of this library, all the examples used the component returned by render method. Now the examples use the screen object.

Both screen and component share the same method names. Questions:

  1. for the methods named the same on both objects, is there any functional difference between the them?
  2. is it best practice to use screen where possible rather than component
@portothree
Copy link
Contributor

portothree commented Aug 21, 2020

Quoting Kent C. Dodds in Common mistakes with React Testing Library

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).

@timdeschryver
Copy link
Member

timdeschryver commented Aug 21, 2020

A good observation @christianacca !
As @portothree mentioned, we encourage the usage of screen (you should be able to use it everywhere if you're not doing something exotic).
Functionally they both do the same.

@christianacca
Copy link
Author

Thanks guys

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants