diff --git a/packages/mui-joy/src/MenuItem/MenuItem.test.tsx b/packages/mui-joy/src/MenuItem/MenuItem.test.tsx
index a81d2248c07f35..e84712d09d1c52 100644
--- a/packages/mui-joy/src/MenuItem/MenuItem.test.tsx
+++ b/packages/mui-joy/src/MenuItem/MenuItem.test.tsx
@@ -97,7 +97,7 @@ describe('Joy ', () => {
const handler = spy();
render();
- await act(async () => fireEvent[eventName](screen.getByRole('menuitem')));
+ fireEvent[eventName](screen.getByRole('menuitem'));
expect(handler.callCount).to.equal(1);
});
@@ -125,15 +125,15 @@ describe('Joy ', () => {
expect(handleFocus.callCount).to.equal(1);
- await act(async () => fireEvent.keyDown(menuitem));
+ fireEvent.keyDown(menuitem);
expect(handleKeyDown.callCount).to.equal(1);
- await act(async () => fireEvent.keyUp(menuitem));
+ fireEvent.keyUp(menuitem);
expect(handleKeyUp.callCount).to.equal(1);
- act(() => {
+ await act(async () => {
menuitem.blur();
});
diff --git a/packages/mui-material/src/ButtonBase/ButtonBase.test.js b/packages/mui-material/src/ButtonBase/ButtonBase.test.js
index 21d28575b8dc98..569b3d9b4c488e 100644
--- a/packages/mui-material/src/ButtonBase/ButtonBase.test.js
+++ b/packages/mui-material/src/ButtonBase/ButtonBase.test.js
@@ -202,47 +202,47 @@ describe('', () => {
if (typeof Touch !== 'undefined') {
const touch = new Touch({ identifier: 0, target: button, clientX: 0, clientY: 0 });
- await act(async () => fireEvent.touchStart(button, { touches: [touch] }));
+ fireEvent.touchStart(button, { touches: [touch] });
expect(onTouchStart.callCount).to.equal(1);
- await act(async () => fireEvent.touchEnd(button, { touches: [touch] }));
+ fireEvent.touchEnd(button, { touches: [touch] });
expect(onTouchEnd.callCount).to.equal(1);
}
if (canFireDragEvents) {
- await act(async () => fireEvent.dragEnd(button));
+ fireEvent.dragEnd(button);
expect(onDragEnd.callCount).to.equal(1);
}
- await act(async () => fireEvent.mouseDown(button));
+ fireEvent.mouseDown(button);
expect(onMouseDown.callCount).to.equal(1);
- await act(async () => fireEvent.mouseUp(button));
+ fireEvent.mouseUp(button);
expect(onMouseUp.callCount).to.equal(1);
- await act(async () => fireEvent.contextMenu(button));
+ fireEvent.contextMenu(button);
expect(onContextMenu.callCount).to.equal(1);
await user.click(button);
expect(onClick.callCount).to.equal(1);
- act(() => {
+ await act(async () => {
button.focus();
});
expect(onFocus.callCount).to.equal(1);
- await act(async () => fireEvent.keyDown(button));
+ fireEvent.keyDown(button);
expect(onKeyDown.callCount).to.equal(1);
- await act(async () => fireEvent.keyUp(button));
+ fireEvent.keyUp(button);
expect(onKeyUp.callCount).to.equal(1);
- act(() => {
+ await act(async () => {
button.blur();
});
expect(onBlur.callCount).to.equal(1);
- await act(async () => fireEvent.mouseLeave(button));
+ fireEvent.mouseLeave(button);
expect(onMouseLeave.callCount).to.equal(1);
});
});
@@ -359,7 +359,7 @@ describe('', () => {
const button = getByRole('button');
await ripple.startTouch(button);
- act(() => button.blur());
+ await act(async () => button.blur());
expect(button.querySelectorAll('.ripple-visible .child-leaving')).to.have.lengthOf(0);
expect(
@@ -802,7 +802,7 @@ describe('', () => {
});
describe('event: focus', () => {
- it('when disabled should be called onFocus', () => {
+ it('when disabled should be called onFocus', async () => {
const onFocusSpy = spy();
const { getByRole } = render(
@@ -810,14 +810,14 @@ describe('', () => {
,
);
- act(() => {
+ await act(async () => {
getByRole('button').focus();
});
expect(onFocusSpy.callCount).to.equal(1);
});
- it('has a focus-visible polyfill', function test() {
+ it('has a focus-visible polyfill', async function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
// JSDOM doesn't support :focus-visible
this.skip();
@@ -829,7 +829,7 @@ describe('', () => {
expect(button).not.to.have.class(classes.focusVisible);
- act(() => {
+ await act(async () => {
button.focus();
});
@@ -942,9 +942,7 @@ describe('', () => {
await ripple.startFocus(button);
- act(() => {
- fireEvent.keyDown(button, { key: 'Enter' });
- });
+ fireEvent.keyDown(button, { key: 'Enter' });
expect(container.querySelectorAll('.ripple-visible')).to.have.lengthOf(1);
@@ -1007,7 +1005,7 @@ describe('', () => {
});
describe('keyboard accessibility for non interactive elements', () => {
- it('does not call onClick when a spacebar is pressed on the element but prevents the default', () => {
+ it('does not call onClick when a spacebar is pressed on the element but prevents the default', async () => {
const onKeyDown = spy();
const onClickSpy = spy();
const { getByRole } = render(
@@ -1017,11 +1015,12 @@ describe('', () => {
);
const button = getByRole('button');
- act(() => {
+ await act(async () => {
button.focus();
- fireEvent.keyDown(button, {
- key: ' ',
- });
+ });
+
+ fireEvent.keyDown(button, {
+ key: ' ',
});
expect(onClickSpy.callCount).to.equal(0);
@@ -1029,7 +1028,7 @@ describe('', () => {
expect(onKeyDown.firstCall.args[0]).to.have.property('defaultPrevented', true);
});
- it('does call onClick when a spacebar is released on the element', () => {
+ it('does call onClick when a spacebar is released on the element', async () => {
const onClickSpy = spy();
const { getByRole } = render(
@@ -1038,18 +1037,19 @@ describe('', () => {
);
const button = getByRole('button');
- act(() => {
+ await act(async () => {
button.focus();
- fireEvent.keyUp(button, {
- key: ' ',
- });
+ });
+
+ fireEvent.keyUp(button, {
+ key: ' ',
});
expect(onClickSpy.callCount).to.equal(1);
expect(onClickSpy.firstCall.args[0]).to.have.property('defaultPrevented', false);
});
- it('does not call onClick when a spacebar is released and the default is prevented', () => {
+ it('does not call onClick when a spacebar is released and the default is prevented', async () => {
const onClickSpy = spy();
const { getByRole } = render(
', () => {
);
const button = getByRole('button');
- act(() => {
+ await act(async () => {
button.focus();
- fireEvent.keyUp(button, {
- key: ' ',
- });
+ });
+
+ fireEvent.keyUp(button, {
+ key: ' ',
});
expect(onClickSpy.callCount).to.equal(0);
});
- it('calls onClick when Enter is pressed on the element', () => {
+ it('calls onClick when Enter is pressed on the element', async () => {
const onClickSpy = spy();
const { getByRole } = render(
@@ -1086,11 +1087,12 @@ describe('', () => {
);
const button = getByRole('button');
- act(() => {
+ await act(async () => {
button.focus();
- fireEvent.keyDown(button, {
- key: 'Enter',
- });
+ });
+
+ fireEvent.keyDown(button, {
+ key: 'Enter',
});
expect(onClickSpy.calledOnce).to.equal(true);
@@ -1131,7 +1133,7 @@ describe('', () => {
expect(onClickSpy.callCount).to.equal(0);
});
- it('prevents default with an anchor and empty href', () => {
+ it('prevents default with an anchor and empty href', async () => {
const onClickSpy = spy();
const { getByRole } = render(
@@ -1140,16 +1142,17 @@ describe('', () => {
);
const button = getByRole('button');
- act(() => {
+ await act(async () => {
button.focus();
- fireEvent.keyDown(button, { key: 'Enter' });
});
+ fireEvent.keyDown(button, { key: 'Enter' });
+
expect(onClickSpy.calledOnce).to.equal(true);
expect(onClickSpy.firstCall.args[0]).to.have.property('defaultPrevented', true);
});
- it('should ignore anchors with href', () => {
+ it('should ignore anchors with href', async () => {
const onClick = spy();
const onKeyDown = spy();
const { getByText } = render(
@@ -1159,11 +1162,12 @@ describe('', () => {
);
const button = getByText('Hello');
- act(() => {
+ await act(async () => {
button.focus();
- fireEvent.keyDown(button, {
- key: 'Enter',
- });
+ });
+
+ fireEvent.keyDown(button, {
+ key: 'Enter',
});
expect(onClick.callCount).to.equal(0);
@@ -1181,7 +1185,7 @@ describe('', () => {
}
});
- it('should be able to focus visible the button', () => {
+ it('should be able to focus visible the button', async () => {
/**
* @type {React.RefObject}
*/
@@ -1195,7 +1199,7 @@ describe('', () => {
// @ts-ignore
expect(typeof buttonActionsRef.current.focusVisible).to.equal('function');
- act(() => {
+ await act(async () => {
// @ts-ignore
buttonActionsRef.current.focusVisible();
});
diff --git a/packages/mui-material/src/ListItemButton/ListItemButton.test.js b/packages/mui-material/src/ListItemButton/ListItemButton.test.js
index 1a58df4cfc118c..d1ddb64aa6bc21 100644
--- a/packages/mui-material/src/ListItemButton/ListItemButton.test.js
+++ b/packages/mui-material/src/ListItemButton/ListItemButton.test.js
@@ -62,14 +62,15 @@ describe('', () => {
}
});
- it('should merge the class names', () => {
+ it('should merge the class names', async () => {
const { getByRole } = render(
,
);
const button = getByRole('button');
- act(() => {
- fireEvent.keyDown(document.activeElement || document.body, { key: 'Tab' });
+ fireEvent.keyDown(document.activeElement || document.body, { key: 'Tab' });
+
+ await act(async () => {
button.focus();
});
diff --git a/packages/mui-material/src/MenuItem/MenuItem.test.js b/packages/mui-material/src/MenuItem/MenuItem.test.js
index 234fc6db0c36e8..145338a1add652 100644
--- a/packages/mui-material/src/MenuItem/MenuItem.test.js
+++ b/packages/mui-material/src/MenuItem/MenuItem.test.js
@@ -91,11 +91,11 @@ describe('', () => {
expect(handleFocus.callCount).to.equal(1);
- await act(async () => fireEvent.keyDown(menuitem));
+ fireEvent.keyDown(menuitem);
expect(handleKeyDown.callCount).to.equal(1);
- await act(async () => fireEvent.keyUp(menuitem));
+ fireEvent.keyUp(menuitem);
expect(handleKeyUp.callCount).to.equal(1);
diff --git a/packages/mui-material/src/Popper/Popper.test.js b/packages/mui-material/src/Popper/Popper.test.js
index 9a61fe3130fe2b..326b95b2df39ec 100644
--- a/packages/mui-material/src/Popper/Popper.test.js
+++ b/packages/mui-material/src/Popper/Popper.test.js
@@ -1,6 +1,6 @@
import * as React from 'react';
import { expect } from 'chai';
-import { act, createRenderer, fireEvent, screen } from '@mui/internal-test-utils';
+import { createRenderer, fireEvent, screen } from '@mui/internal-test-utils';
import { ThemeProvider } from '@mui/system';
import createTheme from '@mui/system/createTheme';
import Grow from '@mui/material/Grow';
@@ -114,9 +114,7 @@ describe('', () => {
);
expect(screen.getByTestId('placement')).to.have.text('bottom');
- await act(async () => {
- await popperRef.current.setOptions({ placement: 'top' });
- });
+ await popperRef.current.setOptions({ placement: 'top' });
expect(screen.getByTestId('placement')).to.have.text('bottom');
});
diff --git a/packages/mui-material/src/Select/Select.test.js b/packages/mui-material/src/Select/Select.test.js
index 86ffb06d56bd7c..d425e6e82b40c0 100644
--- a/packages/mui-material/src/Select/Select.test.js
+++ b/packages/mui-material/src/Select/Select.test.js
@@ -116,14 +116,15 @@ describe('', () => {
);
const trigger = getByRole('combobox');
- await act(async () => fireEvent.mouseDown(trigger));
+ fireEvent.mouseDown(trigger);
expect(handleBlur.callCount).to.equal(0);
expect(getByRole('listbox')).not.to.equal(null);
+ const options = getAllByRole('option');
+ fireEvent.mouseDown(options[0]);
+
await act(async () => {
- const options = getAllByRole('option');
- fireEvent.mouseDown(options[0]);
options[0].click();
});
@@ -145,14 +146,14 @@ describe('', () => {
});
[' ', 'ArrowUp', 'ArrowDown', 'Enter'].forEach((key) => {
- it(`should open menu when pressed ${key} key on select`, () => {
+ it(`should open menu when pressed ${key} key on select`, async () => {
render(
,
);
const trigger = screen.getByRole('combobox');
- act(() => {
+ await act(async () => {
trigger.focus();
});
@@ -164,7 +165,7 @@ describe('', () => {
});
});
- it('should pass "name" as part of the event.target for onBlur', () => {
+ it('should pass "name" as part of the event.target for onBlur', async () => {
const handleBlur = stub().callsFake((event) => event.target.name);
const { getByRole } = render(
,
);
const button = getByRole('combobox');
- act(() => {
+ await act(async () => {
button.focus();
- });
-
- act(() => {
button.blur();
});
@@ -184,7 +182,7 @@ describe('', () => {
expect(handleBlur.firstCall.returnValue).to.equal('blur-testing');
});
- it('should call onClose when the backdrop is clicked', () => {
+ it('should call onClose when the backdrop is clicked', async () => {
const handleClose = spy();
const { getByTestId } = render(
', () => {
,
);
- act(() => {
+ await act(async () => {
getByTestId('backdrop').click();
});
@@ -243,7 +241,7 @@ describe('', () => {
});
describe('prop: onChange', () => {
- it('should get selected element from arguments', () => {
+ it('should get selected element from arguments', async () => {
const onChangeHandler = spy();
const { getAllByRole, getByRole } = render(
@@ -253,7 +251,7 @@ describe('', () => {
,
);
fireEvent.mouseDown(getByRole('combobox'));
- act(() => {
+ await act(async () => {
getAllByRole('option')[1].click();
});
@@ -262,7 +260,7 @@ describe('', () => {
expect(React.isValidElement(selected)).to.equal(true);
});
- it('should call onChange before onClose', () => {
+ it('should call onChange before onClose', async () => {
const eventLog = [];
const onChangeHandler = spy(() => eventLog.push('CHANGE_EVENT'));
const onCloseHandler = spy(() => eventLog.push('CLOSE_EVENT'));
@@ -274,14 +272,14 @@ describe('', () => {
);
fireEvent.mouseDown(getByRole('combobox'));
- act(() => {
+ await act(async () => {
getAllByRole('option')[1].click();
});
expect(eventLog).to.deep.equal(['CHANGE_EVENT', 'CLOSE_EVENT']);
});
- it('should not be called if selected element has the current value (value did not change)', () => {
+ it('should not be called if selected element has the current value (value did not change)', async () => {
const onChangeHandler = spy();
const { getAllByRole, getByRole } = render(
@@ -291,7 +289,7 @@ describe('', () => {
,
);
fireEvent.mouseDown(getByRole('combobox'));
- act(() => {
+ await act(async () => {
getAllByRole('option')[1].click();
});
@@ -479,10 +477,10 @@ describe('', () => {
expect(getByRole('combobox', { hidden: true })).to.have.attribute('aria-controls', listboxId);
});
- specify('the listbox is focusable', () => {
+ specify('the listbox is focusable', async () => {
const { getByRole } = render();
- act(() => {
+ await act(async () => {
getByRole('listbox').focus();
});
@@ -529,11 +527,9 @@ describe('', () => {
const options = getAllByRole('option');
expect(options[1]).to.have.attribute('tabindex', '0');
- act(() => {
- fireEvent.keyDown(options[1], { key: 'ArrowDown' });
- fireEvent.keyDown(options[2], { key: 'ArrowDown' });
- fireEvent.keyDown(options[4], { key: 'Enter' });
- });
+ fireEvent.keyDown(options[1], { key: 'ArrowDown' });
+ fireEvent.keyDown(options[2], { key: 'ArrowDown' });
+ fireEvent.keyDown(options[4], { key: 'Enter' });
expect(options[4]).to.have.attribute('aria-selected', 'true');
});
@@ -555,11 +551,9 @@ describe('', () => {
const options = getAllByRole('option');
expect(options[2]).to.have.attribute('tabindex', '0');
- act(() => {
- fireEvent.keyDown(options[2], { key: 'ArrowDown' });
- fireEvent.keyDown(options[3], { key: 'ArrowDown' });
- fireEvent.keyDown(options[5], { key: 'Enter' });
- });
+ fireEvent.keyDown(options[2], { key: 'ArrowDown' });
+ fireEvent.keyDown(options[3], { key: 'ArrowDown' });
+ fireEvent.keyDown(options[5], { key: 'Enter' });
expect(options[5]).to.have.attribute('aria-selected', 'true');
});
@@ -582,11 +576,9 @@ describe('', () => {
const options = getAllByRole('option');
expect(options[1]).to.have.attribute('tabindex', '0');
- act(() => {
- fireEvent.keyDown(options[1], { key: 'ArrowDown' });
- fireEvent.keyDown(options[2], { key: 'ArrowDown' });
- fireEvent.keyDown(options[4], { key: 'Enter' });
- });
+ fireEvent.keyDown(options[1], { key: 'ArrowDown' });
+ fireEvent.keyDown(options[2], { key: 'ArrowDown' });
+ fireEvent.keyDown(options[4], { key: 'Enter' });
expect(options[4]).to.have.attribute('aria-selected', 'true');
});
@@ -610,11 +602,9 @@ describe('', () => {
const options = getAllByRole('option');
expect(options[1]).to.have.attribute('tabindex', '0');
- act(() => {
- fireEvent.keyDown(options[1], { key: 'ArrowDown' });
- fireEvent.keyDown(options[2], { key: 'ArrowDown' });
- fireEvent.keyDown(options[4], { key: 'Enter' });
- });
+ fireEvent.keyDown(options[1], { key: 'ArrowDown' });
+ fireEvent.keyDown(options[2], { key: 'ArrowDown' });
+ fireEvent.keyDown(options[4], { key: 'Enter' });
expect(options[4]).to.have.attribute('aria-selected', 'true');
});
@@ -690,11 +680,9 @@ describe('', () => {
const options = getAllByRole('option');
expect(options[2]).to.have.attribute('tabindex', '0');
- act(() => {
- fireEvent.keyDown(options[2], { key: 'ArrowDown' });
- fireEvent.keyDown(options[3], { key: 'ArrowDown' });
- fireEvent.keyDown(options[5], { key: 'Enter' });
- });
+ fireEvent.keyDown(options[2], { key: 'ArrowDown' });
+ fireEvent.keyDown(options[3], { key: 'ArrowDown' });
+ fireEvent.keyDown(options[5], { key: 'Enter' });
expect(options[5]).to.have.attribute('aria-selected', 'true');
});
@@ -784,7 +772,7 @@ describe('', () => {
});
describe('prop: readOnly', () => {
- it('should not trigger any event with readOnly', () => {
+ it('should not trigger any event with readOnly', async () => {
render(
@@ -792,7 +780,7 @@ describe('', () => {
,
);
const trigger = screen.getByRole('combobox');
- act(() => {
+ await act(async () => {
trigger.focus();
});
@@ -940,7 +928,7 @@ describe('', () => {
});
describe('prop: open (controlled)', () => {
- it('should not focus on close controlled select', () => {
+ it('should not focus on close controlled select', async () => {
function ControlledWrapper() {
const [open, setOpen] = React.useState(false);
@@ -962,7 +950,7 @@ describe('', () => {
}
const { container, getByRole } = render();
const openSelect = container.querySelector('#open-select');
- act(() => {
+ await act(async () => {
openSelect.focus();
});
fireEvent.click(openSelect);
@@ -975,7 +963,7 @@ describe('', () => {
expect(openSelect).toHaveFocus();
});
- it('should allow to control closing by passing onClose props', () => {
+ it('should allow to control closing by passing onClose props', async () => {
function ControlledWrapper() {
const [open, setOpen] = React.useState(false);
@@ -996,7 +984,7 @@ describe('', () => {
fireEvent.mouseDown(getByRole('combobox'));
expect(getByRole('listbox')).not.to.equal(null);
- act(() => {
+ await act(async () => {
getByRole('option').click();
});
// react-transition-group uses one extra commit for exit to completely remove
@@ -1199,7 +1187,7 @@ describe('', () => {
});
describe('prop: onChange', () => {
- it('should call onChange when clicking an item', () => {
+ it('should call onChange when clicking an item', async () => {
function ControlledSelectInput(props) {
const { onChange } = props;
const [values, clickedValue] = React.useReducer((currentValues, valueClicked) => {
@@ -1239,7 +1227,7 @@ describe('', () => {
expect(onChange.callCount).to.equal(1);
expect(onChange.firstCall.returnValue).to.deep.equal({ name: 'age', value: [30] });
- act(() => {
+ await act(async () => {
options[0].click();
});
@@ -1332,11 +1320,11 @@ describe('', () => {
// TODO: This might be confusing a prop called input!Ref can imperatively
// focus a button. This implies is still used.
- it('should be able focus the trigger imperatively', () => {
+ it('should be able focus the trigger imperatively', async () => {
const ref = React.createRef();
const { getByRole } = render();
- act(() => {
+ await act(async () => {
ref.current.focus();
});
@@ -1573,7 +1561,7 @@ describe('', () => {
});
describe('form submission', () => {
- it('includes Select value in formData only if the `name` attribute is provided', function test() {
+ it('includes Select value in formData only if the `name` attribute is provided', async function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
// FormData is not available in JSDOM
this.skip();
@@ -1602,7 +1590,7 @@ describe('', () => {
);
const button = getByText('Submit');
- act(() => {
+ await act(async () => {
button.click();
});
});
diff --git a/packages/mui-material/src/SpeedDial/SpeedDial.test.js b/packages/mui-material/src/SpeedDial/SpeedDial.test.js
index 837a3381d3933b..ce2d3a804a2764 100644
--- a/packages/mui-material/src/SpeedDial/SpeedDial.test.js
+++ b/packages/mui-material/src/SpeedDial/SpeedDial.test.js
@@ -123,11 +123,15 @@ describe('', () => {
,
);
const buttonWrapper = getByRole('button', { expanded: true });
+
+ fireEvent.keyDown(document.body, { key: 'TAB' });
+
await act(async () => {
- fireEvent.keyDown(document.body, { key: 'TAB' });
buttonWrapper.focus();
- fireEvent.keyDown(buttonWrapper, { key: ' ' });
});
+
+ fireEvent.keyDown(buttonWrapper, { key: ' ' });
+
expect(handleKeyDown.callCount).to.equal(1);
expect(handleKeyDown.args[0][0]).to.have.property('key', ' ');
});
@@ -190,7 +194,7 @@ describe('', () => {
expect(handleOpen.callCount).to.equal(1);
const actions = getAllByRole('menuitem');
expect(actions.length).to.equal(2);
- await act(async () => fireEvent.keyDown(fab, { key: 'ArrowUp' }));
+ fireEvent.keyDown(fab, { key: 'ArrowUp' });
expect(document.activeElement).to.equal(actions[0]);
expect(fab).to.have.attribute('aria-expanded', 'true');
});
@@ -218,11 +222,11 @@ describe('', () => {
expect(fab).to.have.attribute('aria-expanded', 'true');
- await act(async () => fireEvent.keyDown(fab, { key: 'ArrowUp' }));
+ fireEvent.keyDown(fab, { key: 'ArrowUp' });
clock.runAll();
expect(queryByRole('tooltip')).not.to.equal(null);
- await act(async () => fireDiscreteEvent.keyDown(actions[0], { key: 'Escape' }));
+ fireDiscreteEvent.keyDown(actions[0], { key: 'Escape' });
clock.runAll();
expect(queryByRole('tooltip')).to.equal(null);
@@ -312,13 +316,13 @@ describe('', () => {
it('considers arrow keys with the same initial orientation', async () => {
await renderSpeedDial();
- await act(async () => fireEvent.keyDown(fabButton, { key: 'left' }));
+ fireEvent.keyDown(fabButton, { key: 'left' });
expect(isActionFocused(0)).to.equal(true);
- await act(async () => fireEvent.keyDown(getActionButton(0), { key: 'up' }));
+ fireEvent.keyDown(getActionButton(0), { key: 'up' });
expect(isActionFocused(0)).to.equal(true);
- await act(async () => fireEvent.keyDown(getActionButton(0), { key: 'left' }));
+ fireEvent.keyDown(getActionButton(0), { key: 'left' });
expect(isActionFocused(1)).to.equal(true);
- await act(async () => fireEvent.keyDown(getActionButton(1), { key: 'right' }));
+ fireEvent.keyDown(getActionButton(1), { key: 'right' });
expect(isActionFocused(0)).to.equal(true);
});
@@ -333,7 +337,7 @@ describe('', () => {
await renderSpeedDial(dialDirection);
- await act(async () => fireEvent.keyDown(fabButton, { key: firstKey }));
+ fireEvent.keyDown(fabButton, { key: firstKey });
expect(isActionFocused(firstFocusedAction)).to.equal(
true,
`focused action initial ${firstKey} should be ${firstFocusedAction}`,
@@ -345,12 +349,9 @@ describe('', () => {
const expectedFocusedAction = foci[i];
const combinationUntilNot = [firstKey, ...combination.slice(0, i + 1)];
- // eslint-disable-next-line no-await-in-loop
- await act(async () =>
- fireEvent.keyDown(getActionButton(previousFocusedAction), {
- key: arrowKey,
- }),
- );
+ fireEvent.keyDown(getActionButton(previousFocusedAction), {
+ key: arrowKey,
+ });
expect(isActionFocused(expectedFocusedAction)).to.equal(
true,
`focused action after ${combinationUntilNot.join(
diff --git a/packages/mui-material/src/Tabs/Tabs.test.js b/packages/mui-material/src/Tabs/Tabs.test.js
index 42e141f71b79d5..5324acf9245dc4 100644
--- a/packages/mui-material/src/Tabs/Tabs.test.js
+++ b/packages/mui-material/src/Tabs/Tabs.test.js
@@ -933,7 +933,7 @@ describe('', () => {
firstTab.focus();
});
- await act(async () => fireEvent.keyDown(firstTab, { key: previousItemKey }));
+ fireEvent.keyDown(firstTab, { key: previousItemKey });
expect(lastTab).toHaveFocus();
expect(handleChange.callCount).to.equal(0);
@@ -963,7 +963,7 @@ describe('', () => {
firstTab.focus();
});
- await act(async () => fireEvent.keyDown(firstTab, { key: previousItemKey }));
+ fireEvent.keyDown(firstTab, { key: previousItemKey });
expect(lastTab).toHaveFocus();
expect(handleChange.callCount).to.equal(1);
@@ -993,7 +993,7 @@ describe('', () => {
secondTab.focus();
});
- await act(async () => fireEvent.keyDown(secondTab, { key: previousItemKey }));
+ fireEvent.keyDown(secondTab, { key: previousItemKey });
expect(firstTab).toHaveFocus();
expect(handleChange.callCount).to.equal(0);
@@ -1023,7 +1023,7 @@ describe('', () => {
secondTab.focus();
});
- await act(async () => fireEvent.keyDown(secondTab, { key: previousItemKey }));
+ fireEvent.keyDown(secondTab, { key: previousItemKey });
expect(firstTab).toHaveFocus();
expect(handleChange.callCount).to.equal(1);
@@ -1052,7 +1052,7 @@ describe('', () => {
lastTab.focus();
});
- await act(async () => fireEvent.keyDown(lastTab, { key: previousItemKey }));
+ fireEvent.keyDown(lastTab, { key: previousItemKey });
expect(firstTab).toHaveFocus();
expect(handleKeyDown.callCount).to.equal(1);
@@ -1082,7 +1082,7 @@ describe('', () => {
lastTab.focus();
});
- await act(async () => fireEvent.keyDown(lastTab, { key: nextItemKey }));
+ fireEvent.keyDown(lastTab, { key: nextItemKey });
expect(firstTab).toHaveFocus();
expect(handleChange.callCount).to.equal(0);
@@ -1112,7 +1112,7 @@ describe('', () => {
lastTab.focus();
});
- await act(async () => fireEvent.keyDown(lastTab, { key: nextItemKey }));
+ fireEvent.keyDown(lastTab, { key: nextItemKey });
expect(firstTab).toHaveFocus();
expect(handleChange.callCount).to.equal(1);
@@ -1142,7 +1142,7 @@ describe('', () => {
secondTab.focus();
});
- await act(async () => fireEvent.keyDown(secondTab, { key: nextItemKey }));
+ fireEvent.keyDown(secondTab, { key: nextItemKey });
expect(lastTab).toHaveFocus();
expect(handleChange.callCount).to.equal(0);
@@ -1172,7 +1172,7 @@ describe('', () => {
secondTab.focus();
});
- await act(async () => fireEvent.keyDown(secondTab, { key: nextItemKey }));
+ fireEvent.keyDown(secondTab, { key: nextItemKey });
expect(lastTab).toHaveFocus();
expect(handleChange.callCount).to.equal(1);
@@ -1201,7 +1201,7 @@ describe('', () => {
firstTab.focus();
});
- await act(async () => fireEvent.keyDown(firstTab, { key: nextItemKey }));
+ fireEvent.keyDown(firstTab, { key: nextItemKey });
expect(lastTab).toHaveFocus();
expect(handleKeyDown.callCount).to.equal(1);
@@ -1228,7 +1228,7 @@ describe('', () => {
lastTab.focus();
});
- await act(async () => fireEvent.keyDown(lastTab, { key: 'Home' }));
+ fireEvent.keyDown(lastTab, { key: 'Home' });
expect(firstTab).toHaveFocus();
expect(handleChange.callCount).to.equal(0);
@@ -1251,7 +1251,7 @@ describe('', () => {
lastTab.focus();
});
- await act(async () => fireEvent.keyDown(lastTab, { key: 'Home' }));
+ fireEvent.keyDown(lastTab, { key: 'Home' });
expect(firstTab).toHaveFocus();
expect(handleChange.callCount).to.equal(1);
@@ -1274,7 +1274,7 @@ describe('', () => {
lastTab.focus();
});
- await act(async () => fireEvent.keyDown(lastTab, { key: 'Home' }));
+ fireEvent.keyDown(lastTab, { key: 'Home' });
expect(secondTab).toHaveFocus();
expect(handleKeyDown.callCount).to.equal(1);
@@ -1298,7 +1298,7 @@ describe('', () => {
firstTab.focus();
});
- await act(async () => fireEvent.keyDown(firstTab, { key: 'End' }));
+ fireEvent.keyDown(firstTab, { key: 'End' });
expect(lastTab).toHaveFocus();
expect(handleChange.callCount).to.equal(0);
@@ -1321,7 +1321,7 @@ describe('', () => {
firstTab.focus();
});
- await act(async () => fireEvent.keyDown(firstTab, { key: 'End' }));
+ fireEvent.keyDown(firstTab, { key: 'End' });
expect(lastTab).toHaveFocus();
expect(handleChange.callCount).to.equal(1);
@@ -1344,7 +1344,7 @@ describe('', () => {
firstTab.focus();
});
- await act(async () => fireEvent.keyDown(firstTab, { key: 'End' }));
+ fireEvent.keyDown(firstTab, { key: 'End' });
expect(secondTab).toHaveFocus();
expect(handleKeyDown.callCount).to.equal(1);
diff --git a/packages/mui-material/src/Tooltip/Tooltip.test.js b/packages/mui-material/src/Tooltip/Tooltip.test.js
index 51122e1360bc19..69cb616337e416 100644
--- a/packages/mui-material/src/Tooltip/Tooltip.test.js
+++ b/packages/mui-material/src/Tooltip/Tooltip.test.js
@@ -414,7 +414,7 @@ describe('', () => {
expect(screen.queryByRole('tooltip')).to.equal(null);
});
- it('should open on long press', () => {
+ it('should open on long press', async () => {
const enterTouchDelay = 700;
const enterDelay = 100;
const leaveTouchDelay = 1500;
@@ -436,7 +436,7 @@ describe('', () => {
expect(screen.getByRole('tooltip')).toBeVisible();
fireEvent.touchEnd(screen.getByRole('button'));
- act(() => {
+ await act(async () => {
screen.getByRole('button').blur();
});
clock.tick(leaveTouchDelay);
@@ -530,7 +530,7 @@ describe('', () => {
expect(screen.getByRole('tooltip')).toBeVisible();
});
- it('should use hysteresis with the enterDelay', () => {
+ it('should use hysteresis with the enterDelay', async () => {
render(
', () => {
expect(screen.getByRole('tooltip')).toBeVisible();
- act(() => {
+ await act(async () => {
document.activeElement.blur();
});
clock.tick(5);
@@ -565,14 +565,14 @@ describe('', () => {
// Bypass `enterDelay` wait, use `enterNextDelay`.
expect(screen.queryByRole('tooltip')).to.equal(null);
- act(() => {
+ await act(async () => {
clock.tick(30);
});
expect(screen.getByRole('tooltip')).toBeVisible();
});
- it('should take the leaveDelay into account', () => {
+ it('should take the leaveDelay into account', async () => {
const leaveDelay = 111;
const enterDelay = 0;
const transitionTimeout = 10;
@@ -595,7 +595,7 @@ describe('', () => {
expect(screen.getByRole('tooltip')).toBeVisible();
- act(() => {
+ await act(async () => {
screen.getByRole('button').blur();
});
@@ -632,7 +632,7 @@ describe('', () => {
});
});
- it(`should be transparent for the focus and blur event`, function test() {
+ it(`should be transparent for the focus and blur event`, async function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
// JSDOM doesn't support :focus-visible
this.skip();
@@ -649,14 +649,14 @@ describe('', () => {
);
const button = screen.getByRole('button');
- act(() => {
+ await act(async () => {
button.focus();
});
expect(handleBlur.callCount).to.equal(0);
expect(handleFocus.callCount).to.equal(1);
- act(() => {
+ await act(async () => {
button.blur();
});
@@ -890,7 +890,7 @@ describe('', () => {
}
});
- it('ignores base focus', () => {
+ it('ignores base focus', async () => {
render(
@@ -900,7 +900,7 @@ describe('', () => {
expect(screen.queryByRole('tooltip')).to.equal(null);
- act(() => {
+ await act(async () => {
screen.getByRole('button').focus();
});
@@ -928,7 +928,7 @@ describe('', () => {
expect(eventLog).to.deep.equal(['focus', 'open']);
});
- it('closes on blur', () => {
+ it('closes on blur', async () => {
const eventLog = [];
const transitionTimeout = 0;
render(
@@ -945,10 +945,10 @@ describe('', () => {
);
const button = screen.getByRole('button');
- act(() => {
+ await act(async () => {
button.focus();
});
- act(() => {
+ await act(async () => {
button.blur();
});
clock.tick(transitionTimeout);
@@ -958,7 +958,7 @@ describe('', () => {
});
// https://github.com/mui/material-ui/issues/19883
- it('should not prevent event handlers of children', () => {
+ it('should not prevent event handlers of children', async () => {
const handleFocus = spy((event) => event.currentTarget);
// Tooltip should not assume that event handlers of children are attached to the
// outermost host
@@ -977,7 +977,7 @@ describe('', () => {
);
const input = screen.getByRole('textbox');
- act(() => {
+ await act(async () => {
input.focus();
});
@@ -987,7 +987,7 @@ describe('', () => {
});
// https://github.com/mui/mui-x/issues/12248
- it('should support event handlers with extra parameters', () => {
+ it('should support event handlers with extra parameters', async () => {
const handleFocus = spy((event, extra) => extra);
const handleBlur = spy((event, ...params) => params);
@@ -1010,14 +1010,14 @@ describe('', () => {
);
const input = screen.getByRole('textbox');
- act(() => {
+ await act(async () => {
input.focus();
});
expect(handleFocus.callCount).to.equal(1);
expect(handleFocus.returnValues[0]).to.equal('focus');
- act(() => {
+ await act(async () => {
input.blur();
});
diff --git a/packages/mui-material/test/integration/Menu.test.js b/packages/mui-material/test/integration/Menu.test.js
index 996c589e313696..e27eff1e2fd37b 100644
--- a/packages/mui-material/test/integration/Menu.test.js
+++ b/packages/mui-material/test/integration/Menu.test.js
@@ -105,22 +105,22 @@ describe(' integration', () => {
});
const menuitems = getAllByRole('menuitem');
- await act(async () => fireEvent.keyDown(menuitems[0], { key: 'ArrowDown' }));
+ fireEvent.keyDown(menuitems[0], { key: 'ArrowDown' });
expect(menuitems[1]).toHaveFocus();
- await act(async () => fireEvent.keyDown(menuitems[1], { key: 'ArrowUp' }));
+ fireEvent.keyDown(menuitems[1], { key: 'ArrowUp' });
expect(menuitems[0]).toHaveFocus();
- await act(async () => fireEvent.keyDown(menuitems[0], { key: 'ArrowUp' }));
+ fireEvent.keyDown(menuitems[0], { key: 'ArrowUp' });
expect(menuitems[2]).toHaveFocus();
- await act(async () => fireEvent.keyDown(menuitems[2], { key: 'Home' }));
+ fireEvent.keyDown(menuitems[2], { key: 'Home' });
expect(menuitems[0]).toHaveFocus();
- await act(async () => fireEvent.keyDown(menuitems[0], { key: 'End' }));
+ fireEvent.keyDown(menuitems[0], { key: 'End' });
expect(menuitems[2]).toHaveFocus();
- await act(async () => fireEvent.keyDown(menuitems[2], { key: 'ArrowRight' }));
+ fireEvent.keyDown(menuitems[2], { key: 'ArrowRight' });
expect(menuitems[2], 'no change on unassociated keys').toHaveFocus();
});
@@ -318,7 +318,7 @@ describe(' integration', () => {
});
// react-transition-group uses one commit per state transition so we need to wait a bit
- await act(async () => fireEvent.keyDown(screen.getAllByRole('menuitem')[0], { key: 'Tab' }));
+ fireEvent.keyDown(screen.getAllByRole('menuitem')[0], { key: 'Tab' });
clock.tick(0);
expect(screen.getByRole('menu', { hidden: true })).toBeInaccessible();
@@ -330,10 +330,9 @@ describe(' integration', () => {
await act(async () => {
button.focus();
button.click();
+ getByTestId('Backdrop').click();
});
- await act(async () => getByTestId('Backdrop').click());
-
expect(getByRole('menu', { hidden: true })).toBeInaccessible();
});
});