-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Components: Improve BorderBoxControl
tests
#45208
Conversation
Size Change: 0 B Total Size: 1.28 MB ℹ️ View Unchanged
|
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.
Great great work 🚀
It would be interesting to understand why the should omit style options when requested
is erroring with a timeout
<BorderBoxControl { ...props } value={ defaultBorder } /> | ||
); | ||
|
||
const widthInput = screen.getByRole( 'spinbutton' ); |
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.
It would even better if the spinbutton
had a name
that we could use in the query (like we do for other buttons).
This change would apply for all of the screen.getByRole( 'spinbutton' )
queries throughout the file
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.
Thanks, that's a good call! I've addressed that in 21ad8ad and actually did it for a few more of the elements we're querying. Looks much better now! 🙌
await user.click( colorButtons[ 0 ] ); | ||
assertStyleOptionsMissing(); | ||
await user.click( colorButtons[ 0 ] ); | ||
|
||
await user.click( colorButtons[ 1 ] ); | ||
assertStyleOptionsMissing(); | ||
await user.click( colorButtons[ 1 ] ); | ||
|
||
await user.click( colorButtons[ 2 ] ); | ||
assertStyleOptionsMissing(); | ||
await user.click( colorButtons[ 2 ] ); | ||
|
||
await user.click( colorButtons[ 3 ] ); | ||
assertStyleOptionsMissing(); | ||
await user.click( colorButtons[ 3 ] ); |
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.
It looks like this test is timing out — could it be somehow related to the refactor from forEach
to a linear set of instructions?
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 think that's the reason - the user-event clicks are much more complicated than just simulating a single event. And because there's quite a few here, plus quite a few assertions between every click pair, this could take longer on some setups. For example, I never got to fail it locally. I've increased the timeout in 4e6c822 to fix this, but since we're working with fake timers, it doesn't make the test slower, so we're good.
4e6c822
to
abc6cbd
Compare
abc6cbd
to
67c344f
Compare
What?
This PR improves the
BorderBoxControl
component tests.Why?
This helps the tests to follow the best practices for writing RTL tests and improves the code quality.
How?
We're enhancing a few different items in these tests:
@testing-library/user-event
instead offireEvent
- primary motivation for this PR.render()
in separate helper functions, rather run them inline.screen
queries in separate helper functions either.Testing Instructions
Verify tests still pass:
npm run test:unit packages/components/src/border-box-control/test/index.js