-
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 Button component tests #651
test(component): refactor Button component tests #651
Conversation
Hey @bc-alexsaiannyi if this is a draft PR, would you mind using the Draft Pull Request feature instead of appending |
36652ef
to
07824c6
Compare
@chanceaclark , sorry. I will do it next time. This time you can check my changes) |
|
||
fireEvent.click(button); | ||
fireEvent.click(screen.getByRole<HTMLButtonElement>('button')); |
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.
Let's also switch out usages of fireEvent
with userEvent
.
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.
Yeah, it's a good point. I also see that we will need @testing-library/user-event package for this purpose. Is it ok to proceed?
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.
For sure
<Button iconLeft={plusIcon} iconOnly={plusIcon} iconRight={plusIcon}> | ||
Button | ||
</Button>, | ||
); | ||
|
||
expect(getAllByTestId('icon-only').length).toBe(1); | ||
expect(screen.getAllByTestId('icon-only').length).toBe(1); |
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.
expect(screen.getAllByTestId('icon-only').length).toBe(1); | |
expect(screen.getAllByTestId('icon-only')).toHaveLength(1); |
b0b246d
to
1525ec8
Compare
1525ec8
to
86d0cbb
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.
Thank you 🙇
What?
This PR is aimed to refactor Button 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
.NOTE: We've also switched to using
userEvent
instead offireEvent
whenever it's possible. For this purpose a package@testing-library/user-event
has been added andyarn.lock
is updated as well.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.