Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
test: CollectionControl #13656
test: CollectionControl #13656
Changes from 1 commit
e8c2910
a073bd9
134e298
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a tip, if you can't assign any reasonable role to the container component, you can always access it using:
😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, but I avoid using
const {container} = render()
as much as possible. I find it more reliable to use screen methods. I've had some problems with containers, so I avoid them whenever is possible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious what sort of problems you were running into there that might be worth avoiding them for. I like @michael-s-molina 's implementation - it's clean, and it makes less noise in the DOM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rusackas It was not in this specific case. But in the past I've had problems that
container
had a very different result thanscreen
. Asscreen
is theoretically the HTML that will be rendered in the browser, I prefer to use it. Any change in behavior or configuration will not change the test result. That way I'm sure the test is right.I only use
container
when I'm doing unit tests, and even in these cases I avoid it as much as possible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yardz I don't know if in the past the implementation was different. Nowadays it's very similar. It will be different when we specify a
container
forrender
that is not the default.Kent C. Dodds in his excellent article Common mistakes with React Testing Library recommends using
screen
whenever possible to avoid destructuring.I also think we should always use
screen
. That being said, in the case where we CANNOT find a satisfactory role/text/placeholder for our top component and we just want to test that thediv
has rendered, bothtest-id
orcontainer
are valid options. Since both options are not accessible, I prefer the one where we don't leave fingerprints in the component's code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice post, several tips!
Well, I don't think that adding this test-id has any negative side effects at any level so the discussion comes down to "use or not the test-id." When it comes down to that it seems to me more like a discussion of "taste" than of "good practices".
If you think this is a block for the merge I can change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yardz For me, it's not a blocker as indicated by the ✔️.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not seen it haha