-
Notifications
You must be signed in to change notification settings - Fork 16.3k
test(useThemeMenuItems): fix race conditions by awaiting all userEvent calls #35918
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
Code Review Agent Run #84dadaActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
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.
…race conditions Fixed 20 unawaited userEvent calls (16 hover + 4 click) that could cause race conditions between user interactions and assertions. This ensures menu rendering completes before queries execute, preventing intermittent test failures. Pattern follows commit 4932f3522f which fixed the same issue in DatasourceControl tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
49653de to
3eccd57
Compare
Interaction Diagram by BitosequenceDiagram
participant TestRunner as Test Runner
participant TestFile as useThemeMenuItems.test.tsx<br/>🔄 Updated | ●●○ Medium
participant UserEvent as userEvent (Testing Library)<br/>●●○ Medium
participant ScreenAPI as screen (Testing Library)
participant Hook as useThemeMenuItems Hook
participant Component as TestComponent
Note over TestFile: All userEvent.hover() and<br/>userEvent.click() calls now awaited
TestRunner->>TestFile: Execute test suite
TestFile->>Component: renderThemeMenu()
Component->>Hook: useThemeMenuItems(props)
Hook-->>Component: Return MenuItem
TestFile->>UserEvent: await userEvent.hover(menuitem)
UserEvent-->>TestFile: Hover action completed
TestFile->>ScreenAPI: findByRole/queryByText
ScreenAPI-->>TestFile: Return menu element
TestFile->>UserEvent: await userEvent.click(element)
UserEvent-->>TestFile: Click action completed
TestFile->>TestRunner: Assert results
Critical path: Test Runner -> useThemeMenuItems.test.tsx -> userEvent (Testing Library) -> screen (Testing Library) -> Hook
|
- PropertiesModal.test.tsx: add await to 18+ userEvent calls - FiltersConfigModal.test.tsx: add await to 26 userEvent calls - Fix anti-pattern: remove userEvent from waitFor blocks - Fix cache_timeout test expectation to match API string type - Resolves race condition causing PropertiesModal test failures Root cause: Tests written in 2021 with synchronous userEvent pattern became problematic as components gained more async complexity. Recent changes (PR #33392) made race conditions consistently reproducible. Follows pattern from PR #35717, #35918, and DatasourceControl fixes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- PropertiesModal.test.tsx: add await to 18+ userEvent calls - FiltersConfigModal.test.tsx: add await to 26 userEvent calls - Fix anti-pattern: remove userEvent from waitFor blocks - Fix cache_timeout test expectation to match API string type - Resolves race condition causing PropertiesModal test failures Root cause: Tests written in 2021 with synchronous userEvent pattern became problematic as components gained more async complexity. Recent changes (PR #33392) made race conditions consistently reproducible. Follows pattern from PR #35717, #35918, and DatasourceControl fixes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
SUMMARY
Fixed race conditions in
useThemeMenuItemstest suite by addingawaitto all 20 unawaiteduserEventcalls (16 hover + 4 click). This prevents intermittent test failures caused by queries executing before async user interactions complete.userEvent.hover()calls (16 occurrences)userEvent.click()calls (4 occurrences)BEFORE/AFTER
Before:
After:
TESTING INSTRUCTIONS
Run the test suite multiple times to verify consistency:
Expected result: All 20 tests pass consistently across multiple runs with no race condition warnings.
Validation performed:
ADDITIONAL INFORMATION
This fix addresses potential flakiness by ensuring that async hover and click actions complete before subsequent queries and assertions execute. The @testing-library/user-event library returns Promises for all user interactions, which must be awaited to prevent race conditions.
Similar fixes have been applied across the codebase (28+ test files properly await userEvent calls). This change brings useThemeMenuItems.test.tsx in line with established testing patterns.
🤖 Generated with Claude Code