-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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: Refactor more tests to use real timers #47318
Conversation
Size Change: 0 B Total Size: 1.33 MB ℹ️ View Unchanged
|
Flaky tests detected in ce24334. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3968077875
|
const menu = screen.getByRole( 'menu', { | ||
name: 'Block Name', | ||
} ); | ||
expect( menu ).toBeInTheDocument(); | ||
expect( menu ).not.toBeVisible(); | ||
await waitFor( () => | ||
expect( | ||
screen.getByRole( 'menu', { | ||
name: 'Block Name', | ||
} ) | ||
).toBeVisible() | ||
); |
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'm not sure I understand these changes — previously the test was checking for the menu to be in the document, but not visible, while the new version of the test seems to check that the menu is visible.
Can you explain the rationale here? Thank you!
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.
The previous test was just wrong. If you manually go through the steps, you'll see that both the button and the menu should be visible. The previous test just wasn't properly waiting for the menu to be revealed.
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.
🤦
const menu = screen.getByRole( 'menu', { | ||
name: 'Block Name', | ||
} ); | ||
expect( menu ).toBeInTheDocument(); | ||
expect( menu ).not.toBeVisible(); | ||
await waitFor( () => | ||
expect( | ||
screen.getByRole( 'menu', { | ||
name: 'Block Name', | ||
} ) | ||
).toBeVisible() | ||
); |
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.
Same as previous comment
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.
Replied there
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.
🚀
What?
This PR updates even more component tests to use real timers. This is a follow-up to #46714, #47056, #47144, and #47218.
Why?
We discovered that Jest real timers are preferable when their use is possible, see facebook/react#25889 and the description in #46714.
This post is great writing that explains the rationale in more detail:
https://jsnajdr.wordpress.com/2023/01/11/prefer-jest-real-timers-when-testing-with-react-testing-library/
How?
We're removing the specific
jest.useFakeTimers();
calls. We're also removing the now unnecessaryjest.advanceTimersByTime()
calls and post-test cleanup that we've been doing withjest.runOnlyPendingTimers()
andjest.useRealTimers()
. We're also altering some tests to wait for the appropriate actions before continuing/performing the relevant assertions.Testing Instructions
Verify all tests still pass.
Testing Instructions for Keyboard
None
Screenshots or screencast
None.