-
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: Remove unnecessary act()
from ToolsPanel
tests
#47691
Conversation
Size Change: +726 B (0%) Total Size: 1.31 MB
ℹ️ View Unchanged
|
Flaky tests detected in 51c3c34. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4084567770
|
@@ -172,16 +172,17 @@ const getMenuButton = () => { | |||
* @return {HTMLElement} The menuButton. | |||
*/ | |||
const openDropdownMenu = async () => { | |||
const user = userEvent.setup(); |
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 you think it's fine to setup userEvent
inside a utility function, rather than once per test?
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.
Yes, I believe it's fine because a subsequent userEvent().setup()
will reuse all from the prior call:
- Preparing the document - basically adding some event listeners - it's done only once, and if
prepareDocument()
is called, event listeners will not be recreated. - Attaching clipboard stub to window - will reuse the same stub if it has already been created.
- Retrieving the document - will reuse the same document object.
The only thing it won't reuse is the actually returned config object reference, which we never use directly anyway, so we're good to go.
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 noticed an issue with the type annotation, but otherwise looks good 👍
Co-authored-by: Lena Morita <[email protected]>
What?
This PR cleans up a few unnecessary
act()
calls and improves some of theToolsPanel
tests.Why?
When preparing our tests to work with React 18 we did a bunch of those
act()
calls. It's time to clean them up where possible.How?
fireEvent.click()
calls in favor ofuserEvent.click()
, and those are async.fireEvent
usage and removing it completely from the testsTesting Instructions
Verify tests still pass:
npm run test:unit packages/components/src/tools-panel/test/index.js
Testing Instructions for Keyboard
None
Screenshots or screencast
None