Skip to content

Commit 41e71a9

Browse files
authored
[code-infra] Fix flaky Select test on Webkit (#47728)
1 parent 7ae667c commit 41e71a9

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

packages/mui-material/src/Select/Select.test.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,47 +1947,41 @@ describe('<Select />', () => {
19471947
});
19481948

19491949
it.skipIf(isJsdom())('updates menu minWidth when the trigger resizes while open', async () => {
1950-
// reset fake timers
19511950
clock.restore();
19521951

19531952
render(
1954-
<Select
1955-
value=""
1956-
MenuProps={{
1957-
transitionDuration: 0,
1958-
}}
1959-
>
1953+
<Select value="" MenuProps={{ transitionDuration: 0 }}>
19601954
<MenuItem value="">None</MenuItem>
19611955
<MenuItem value={10}>Ten</MenuItem>
19621956
</Select>,
19631957
);
19641958

19651959
const combobox = screen.getByRole('combobox');
19661960
const anchor = combobox.parentElement;
1967-
1968-
// Give the anchor a deterministic width that will affect clientWidth in a real browser.
19691961
anchor.style.width = '320px';
19701962

19711963
fireEvent.mouseDown(combobox);
19721964

1973-
const width1 = anchor.clientWidth;
1974-
19751965
await waitFor(() => {
19761966
const listbox = screen.getByRole('listbox');
19771967
const paper = listbox.parentElement;
1978-
expect(paper.style.minWidth).to.equal(`${width1}px`);
1968+
expect(paper.style.minWidth).to.equal('320px');
19791969
});
19801970

1981-
// Simulate a "window resize" effect by changing the anchor's width while open.
19821971
anchor.style.width = '180px';
19831972

1973+
// ResizeObserver callbacks are delivered during the browser's rendering pipeline.
1974+
// Force at least one complete frame so the RO can detect the size change,
1975+
await act(async () => {
1976+
await new Promise((resolve) => {
1977+
requestAnimationFrame(() => requestAnimationFrame(resolve));
1978+
});
1979+
});
1980+
19841981
await waitFor(() => {
1985-
const width2 = anchor.clientWidth;
19861982
const listbox = screen.getByRole('listbox');
19871983
const paper = listbox.parentElement;
1988-
1989-
// This is the actual regression assertion:
1990-
expect(paper.style.minWidth).to.equal(`${width2}px`);
1984+
expect(paper.style.minWidth).to.equal('180px');
19911985
});
19921986
});
19931987
});

0 commit comments

Comments
 (0)