-
-
Notifications
You must be signed in to change notification settings - Fork 204
Testing with react-testing-library #51
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
Conversation
src/components/Bar/Bar.spec.js
Outdated
const { container, rerender } = render(<Bar size='sm' />) | ||
const barEl = container.firstChild | ||
|
||
expect(barEl).toHaveStyleRule('height', '27px') |
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.
wouldn't it be better if we compared rendered height to the helper variable that is used to specify Bar components height?
https://github.com/arturbien/React95/blob/ea317b8618e8fd064db8225c558cda9625cb40af/src/components/Bar/Bar.js#L4
https://github.com/arturbien/React95/blob/ea317b8618e8fd064db8225c558cda9625cb40af/src/components/Bar/Bar.js#L9
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 agree with u! Fixed :)
src/components/Button/Button.spec.js
Outdated
expect(onButtonClick).toHaveBeenCalled() | ||
}) | ||
|
||
it('should render disabled', () => { |
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.
Here we should also test other variants of <Button />
. That's because variant="menu"
and variant="flat"
also have the disabled
option. Below links to the Storybook where you can see both variants in disabled and not disabled state:
variant="menu"
variant="flat"
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.
cool, added more test cases for different variants :)
expect(button).toHaveAttribute('type', 'submit') | ||
}) | ||
|
||
it('should handle click properly', () => { |
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.
We should also test if the button with disabled
prop reacts to onClick (when button is disabled it doesn't trigger specified onClick
prop when clicked).
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.
well-observed, thanks!
fixed :)
- Improve Bar tests with blockSizes from commom instead of static values - Test disabled Button callback function
🎉 This PR is included in version 3.0.0-beta.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 3.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Create an initial test structure using
jest
and@testing-library/react
with initial tests for the components:Obs: This is related to #27