Skip to content

Commit f061251

Browse files
LukasTyclaude
andcommitted
[test][docs-infra] Fix flaky runtime theme bridge test in WebKit
The bridge test waited with `waitFor` for a state update that React commits in a scheduler task. On CI WebKit, that task can run after the `waitFor` timeout, so the test failed with the text still "base". Use `flushMicrotasks()` to commit the update inside `act()`. The update then does not depend on the scheduler task. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent bf5e8eb commit f061251

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎packages-internal/core-docs/src/DemoThemeProviders/DemoThemeProviders.test.tsx‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { describe, it, expect } from 'vitest';
22
import * as React from 'react';
3-
import { createRenderer, fireEvent, isJsdom, screen, waitFor } from '@mui/internal-test-utils';
3+
import {
4+
createRenderer,
5+
fireEvent,
6+
flushMicrotasks,
7+
isJsdom,
8+
screen,
9+
waitFor,
10+
} from '@mui/internal-test-utils';
411
import { ThemeProvider, createTheme, useColorScheme, useTheme } from '@mui/material/styles';
512
import Box from '@mui/material/Box';
613
import type * as JsxRuntime from 'react/jsx-runtime';
@@ -92,7 +99,10 @@ describe('docs demo theming', () => {
9299
</ThemeProvider>,
93100
);
94101

95-
await waitFor(() => expect(screen.getByTestId('first')).to.have.text('injected'));
102+
// Commit the bridge update inside `act()`. Outside it, the update waits for a
103+
// scheduler task, and CI WebKit can delay that task past the `waitFor` timeout.
104+
await flushMicrotasks();
105+
expect(screen.getByTestId('first')).to.have.text('injected');
96106
expect(screen.getByTestId('second')).to.have.text('injected');
97107
expect(callCount).to.equal(1);
98108
expect(runtimeWindow.React?.createElement).to.equal(React.createElement);

0 commit comments

Comments
 (0)