-
Notifications
You must be signed in to change notification settings - Fork 65
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(component): refactor Checkbox component tests #655
Conversation
18d08e2
to
a2e99ac
Compare
a2e99ac
to
884bc18
Compare
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.
Looks good, however one minor comment.
const labels = container.querySelectorAll('label'); | ||
render(<Checkbox label="Checked" checked={true} onChange={onChange} />); | ||
|
||
const labels = screen.getByRole<HTMLInputElement>('checkbox').parentElement!.querySelectorAll('label'); |
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.
Could this be screen.getAllByRole('label')
?
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 was also looking on similar approach but looks like such role does not exist
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.
what about getByText(/checked/)
? might still be better than all this... 🤷
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.
In this case we will not catch label
with svg
inside
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.
Totally forgot there is the screen.getByLabelText('')
query 🤦
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.
Query above may return an input associated with the label, but we need to collect all labels and then iterate through them. Can you provide some code according to our component? Maybe I have wrong understanding of your idea
Outdated 👍 |
What?
This PR is aimed to refactor Checkbox component's tests according to best practices. We take into account recommendations from Kent C. Dodds article. For instance, using
container
forquery
-ing elements has been removed. Instead, we replace it withscreen
.Why?
the changes are based on GitHub issue and PRs will be open for each component separately.
Testing/Proof
The tests have been successfully run locally.