Skip to content

Commit 3eccd57

Browse files
sadpandajoeclaude
andcommitted
test(useThemeMenuItems): add await to all userEvent calls to prevent 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>
1 parent 6e27bee commit 3eccd57

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

superset-frontend/src/hooks/useThemeMenuItems.test.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('useThemeMenuItems', () => {
7070
test('renders Light and Dark theme options by default', async () => {
7171
renderThemeMenu();
7272

73-
userEvent.hover(await screen.findByRole('menuitem'));
73+
await userEvent.hover(await screen.findByRole('menuitem'));
7474
const menu = await findMenuWithText('Light');
7575

7676
expect(within(menu!).getByText('Light')).toBeInTheDocument();
@@ -79,7 +79,7 @@ describe('useThemeMenuItems', () => {
7979

8080
test('does not render Match system option when allowOSPreference is false', async () => {
8181
renderThemeMenu({ ...defaultProps, allowOSPreference: false });
82-
userEvent.hover(await screen.findByRole('menuitem'));
82+
await userEvent.hover(await screen.findByRole('menuitem'));
8383

8484
await waitFor(() => {
8585
expect(screen.queryByText('Match system')).not.toBeInTheDocument();
@@ -89,7 +89,7 @@ describe('useThemeMenuItems', () => {
8989
test('renders with allowOSPreference as true by default', async () => {
9090
renderThemeMenu();
9191

92-
userEvent.hover(await screen.findByRole('menuitem'));
92+
await userEvent.hover(await screen.findByRole('menuitem'));
9393
const menu = await findMenuWithText('Match system');
9494

9595
expect(within(menu).getByText('Match system')).toBeInTheDocument();
@@ -103,7 +103,7 @@ describe('useThemeMenuItems', () => {
103103
onClearLocalSettings: mockClear,
104104
});
105105

106-
userEvent.hover(await screen.findByRole('menuitem'));
106+
await userEvent.hover(await screen.findByRole('menuitem'));
107107
const menu = await findMenuWithText('Clear local theme');
108108

109109
expect(within(menu).getByText('Clear local theme')).toBeInTheDocument();
@@ -117,7 +117,7 @@ describe('useThemeMenuItems', () => {
117117
onClearLocalSettings: mockClear,
118118
});
119119

120-
userEvent.hover(await screen.findByRole('menuitem'));
120+
await userEvent.hover(await screen.findByRole('menuitem'));
121121

122122
await waitFor(() => {
123123
expect(screen.queryByText('Clear local theme')).not.toBeInTheDocument();
@@ -128,9 +128,9 @@ describe('useThemeMenuItems', () => {
128128
const mockSet = jest.fn();
129129
renderThemeMenu({ ...defaultProps, setThemeMode: mockSet });
130130

131-
userEvent.hover(await screen.findByRole('menuitem'));
131+
await userEvent.hover(await screen.findByRole('menuitem'));
132132
const menu = await findMenuWithText('Light');
133-
userEvent.click(within(menu).getByText('Light'));
133+
await userEvent.click(within(menu).getByText('Light'));
134134

135135
expect(mockSet).toHaveBeenCalledWith(ThemeMode.DEFAULT);
136136
});
@@ -139,9 +139,9 @@ describe('useThemeMenuItems', () => {
139139
const mockSet = jest.fn();
140140
renderThemeMenu({ ...defaultProps, setThemeMode: mockSet });
141141

142-
userEvent.hover(await screen.findByRole('menuitem'));
142+
await userEvent.hover(await screen.findByRole('menuitem'));
143143
const menu = await findMenuWithText('Dark');
144-
userEvent.click(within(menu).getByText('Dark'));
144+
await userEvent.click(within(menu).getByText('Dark'));
145145

146146
expect(mockSet).toHaveBeenCalledWith(ThemeMode.DARK);
147147
});
@@ -150,9 +150,9 @@ describe('useThemeMenuItems', () => {
150150
const mockSet = jest.fn();
151151
renderThemeMenu({ ...defaultProps, setThemeMode: mockSet });
152152

153-
userEvent.hover(await screen.findByRole('menuitem'));
153+
await userEvent.hover(await screen.findByRole('menuitem'));
154154
const menu = await findMenuWithText('Match system');
155-
userEvent.click(within(menu).getByText('Match system'));
155+
await userEvent.click(within(menu).getByText('Match system'));
156156

157157
expect(mockSet).toHaveBeenCalledWith(ThemeMode.SYSTEM);
158158
});
@@ -165,9 +165,9 @@ describe('useThemeMenuItems', () => {
165165
onClearLocalSettings: mockClear,
166166
});
167167

168-
userEvent.hover(await screen.findByRole('menuitem'));
168+
await userEvent.hover(await screen.findByRole('menuitem'));
169169
const menu = await findMenuWithText('Clear local theme');
170-
userEvent.click(within(menu).getByText('Clear local theme'));
170+
await userEvent.click(within(menu).getByText('Clear local theme'));
171171

172172
expect(mockClear).toHaveBeenCalledTimes(1);
173173
});
@@ -195,7 +195,7 @@ describe('useThemeMenuItems', () => {
195195
test('renders Theme group header', async () => {
196196
renderThemeMenu();
197197

198-
userEvent.hover(await screen.findByRole('menuitem'));
198+
await userEvent.hover(await screen.findByRole('menuitem'));
199199
const menu = await findMenuWithText('Theme');
200200

201201
expect(within(menu).getByText('Theme')).toBeInTheDocument();
@@ -204,7 +204,7 @@ describe('useThemeMenuItems', () => {
204204
test('renders sun icon for Light theme option', async () => {
205205
renderThemeMenu();
206206

207-
userEvent.hover(await screen.findByRole('menuitem'));
207+
await userEvent.hover(await screen.findByRole('menuitem'));
208208
const menu = await findMenuWithText('Light');
209209
const lightOption = within(menu).getByText('Light').closest('li');
210210

@@ -214,7 +214,7 @@ describe('useThemeMenuItems', () => {
214214
test('renders moon icon for Dark theme option', async () => {
215215
renderThemeMenu();
216216

217-
userEvent.hover(await screen.findByRole('menuitem'));
217+
await userEvent.hover(await screen.findByRole('menuitem'));
218218
const menu = await findMenuWithText('Dark');
219219
const darkOption = within(menu).getByText('Dark').closest('li');
220220

@@ -224,7 +224,7 @@ describe('useThemeMenuItems', () => {
224224
test('renders format-painter icon for Match system option', async () => {
225225
renderThemeMenu({ ...defaultProps, allowOSPreference: true });
226226

227-
userEvent.hover(await screen.findByRole('menuitem'));
227+
await userEvent.hover(await screen.findByRole('menuitem'));
228228
const menu = await findMenuWithText('Match system');
229229
const matchOption = within(menu).getByText('Match system').closest('li');
230230

@@ -240,7 +240,7 @@ describe('useThemeMenuItems', () => {
240240
onClearLocalSettings: jest.fn(),
241241
});
242242

243-
userEvent.hover(await screen.findByRole('menuitem'));
243+
await userEvent.hover(await screen.findByRole('menuitem'));
244244
const menu = await findMenuWithText('Clear local theme');
245245
const clearOption = within(menu)
246246
.getByText('Clear local theme')
@@ -256,7 +256,7 @@ describe('useThemeMenuItems', () => {
256256
onClearLocalSettings: jest.fn(),
257257
});
258258

259-
userEvent.hover(await screen.findByRole('menuitem'));
259+
await userEvent.hover(await screen.findByRole('menuitem'));
260260

261261
const menu = await findMenuWithText('Clear local theme');
262262
const divider = within(menu).queryByRole('separator');
@@ -267,7 +267,7 @@ describe('useThemeMenuItems', () => {
267267
test('does not render divider when clear option is not present', async () => {
268268
renderThemeMenu({ ...defaultProps });
269269

270-
userEvent.hover(await screen.findByRole('menuitem'));
270+
await userEvent.hover(await screen.findByRole('menuitem'));
271271
const divider = document.querySelector('.ant-menu-item-divider');
272272

273273
expect(divider).toBeNull();

0 commit comments

Comments
 (0)