-
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 Counter component tests #658
test(component): refactor Counter component tests #658
Conversation
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.
Hey @bc-alexsaiannyi!
Thanks for this PR, looking good, I just added a few comments, let me know what you think about them.
🙇
|
||
const counter = getByDisplayValue('5') as HTMLInputElement; | ||
const counter = screen.getByRole<HTMLInputElement>('textbox'); |
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 don't think the type (HTMLInputElement
) is necessary anywhere in the file, consider removing it.
const item1 = screen.getByTestId<HTMLInputElement>('item1'); | ||
const item2 = screen.getByTestId<HTMLInputElement>('item2'); |
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.
No need to cast them to HTMLInputElement
, all HTMLElements
have id
s
739d0b6
to
623ce36
Compare
Hey @icatalina. I've added changes. Thank you for going through and adding all your suggestions. |
623ce36
to
e425427
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.
Looking good, just a few small comments :)
expect(ref.current).toBe(counter); | ||
render(<Counter value={5} onCountChange={jest.fn()} ref={ref} />); | ||
|
||
const input = screen.getByRole<HTMLInputElement>('textbox'); |
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.
Do we need to cast to HTMLInputElement
?
const { container } = render(counterMock({ max: 20, ...requiredAttributes })); | ||
render(<CounterMock value={5} />); | ||
|
||
const input = screen.getByRole<HTMLInputElement>('textbox'); |
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(container.querySelector('[class*="StyledError"]')).not.toBeInTheDocument(); | ||
expect(screen.queryByText('Error')).not.toBeInTheDocument(); |
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.
Why do we swap between error
and 'Error'
?
e425427
to
911de93
Compare
I'm going to close this since I already did most of it in #1187 |
This PR is aimed to refactor Counter 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.