Repository navigation
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
|
| * @return {HTMLElement} The menuButton. | ||
| */ | ||
| const openDropdownMenu = async () => { | ||
| const user = userEvent.setup(); |
There was a problem hiding this comment.
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.
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.
mirka
left a comment
There was a problem hiding this comment.
I noticed an issue with the type annotation, but otherwise looks good 👍
Co-authored-by: Lena Morita <lena@jaguchi.com>
What?
This PR cleans up a few unnecessary
act()calls and improves some of theToolsPaneltests.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.fireEventusage and removing it completely from the testsTesting Instructions
Verify tests still pass:
npm run test:unit packages/components/src/tools-panel/test/index.jsTesting Instructions for Keyboard
None
Screenshots or screencast
None