{
if (!event.defaultPrevented && event.key === 'Enter') {
@@ -644,7 +644,7 @@ describe('Joy
', () => {
);
let options;
- const textbox = screen.getByRole('combobox');
+ const textbox = getByRole('combobox');
fireEvent.keyDown(textbox, { key: 'ArrowDown' });
fireEvent.keyDown(textbox, { key: 'ArrowDown' });
@@ -909,7 +909,7 @@ describe('Joy
', () => {
,
);
- fireEvent.keyDown(screen.getByRole('combobox'), { key: 'ArrowDown' });
+ fireEvent.keyDown(getByRole('combobox'), { key: 'ArrowDown' });
expect(getByRole('combobox')).to.have.attribute(
'aria-activedescendant',
getAllByRole('option')[0].getAttribute('id')!,
@@ -921,7 +921,7 @@ describe('Joy
', () => {
,
);
- fireEvent.keyDown(screen.getByRole('combobox'), { key: 'ArrowUp' });
+ fireEvent.keyDown(getByRole('combobox'), { key: 'ArrowUp' });
const options = getAllByRole('option');
expect(getByRole('combobox')).to.have.attribute(
'aria-activedescendant',
@@ -932,7 +932,7 @@ describe('Joy
', () => {
it('should ignore keydown event until the IME is confirmed', function test() {
// TODO: Often times out in Firefox 78.
// Is this slow because of testing-library or because of the implementation?
- this.timeout(4000);
+ this?.timeout?.(4000);
const { getByRole } = render(
);
const textbox = getByRole('combobox');
@@ -980,8 +980,10 @@ describe('Joy
', () => {
describe('listbox wrapping behavior', () => {
it('wraps around when navigating the list by default', () => {
- const { getAllByRole } = render(
);
- const textbox = screen.getByRole('combobox');
+ const { getAllByRole, getByRole } = render(
+
,
+ );
+ const textbox = getByRole('combobox');
fireEvent.keyDown(textbox, { key: 'ArrowDown' });
fireEvent.keyDown(textbox, { key: 'ArrowUp' });
@@ -1105,22 +1107,24 @@ describe('Joy
', () => {
});
it('should close the popup when disabled is true', () => {
- const { setProps } = render(
);
- const textbox = screen.getByRole('combobox');
+ const { setProps, getByRole, queryByRole } = render(
+
,
+ );
+ const textbox = getByRole('combobox');
act(() => {
textbox.focus();
});
fireEvent.keyDown(textbox, { key: 'ArrowDown' });
- expect(screen.queryByRole('listbox')).not.to.equal(null);
+ expect(queryByRole('listbox')).not.to.equal(null);
setProps({ disabled: true });
- expect(screen.queryByRole('listbox')).to.equal(null);
+ expect(queryByRole('listbox')).to.equal(null);
});
it('should not crash when autoSelect & freeSolo are set, text is focused & disabled gets truthy', () => {
- const { setProps } = render(
+ const { setProps, getByRole } = render(
,
);
- const textbox = screen.getByRole('combobox');
+ const textbox = getByRole('combobox');
act(() => {
textbox.focus();
});
@@ -1245,13 +1249,13 @@ describe('Joy
', () => {
groupBy={(option) => String(option.group)}
/>,
);
+ const options = screen.getAllByRole('option').map((el) => el.textContent);
+ expect(options).to.have.length(7);
+ expect(options).to.deep.equal(['A', 'D', 'E', 'B', 'G', 'F', 'C']);
}).toWarnDev([
'returns duplicated headers',
!strictModeDoubleLoggingSuppressed && 'returns duplicated headers',
]);
- const options = screen.getAllByRole('option').map((el) => el.textContent);
- expect(options).to.have.length(7);
- expect(options).to.deep.equal(['A', 'D', 'E', 'B', 'G', 'F', 'C']);
});
it('warn if the type of the value is wrong', () => {
@@ -1283,7 +1287,7 @@ describe('Joy
', () => {
describe('prop: options', () => {
it('should scroll selected option into view when multiple elements with role as listbox available', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
render(
@@ -1324,9 +1328,11 @@ describe('Joy
', () => {
});
it('should keep focus on selected option and not reset to top option when options updated', () => {
- const { setProps } = render(
);
- const textbox = screen.getByRole('combobox');
- const listbox = screen.getByRole('listbox');
+ const { setProps, getByRole } = render(
+
,
+ );
+ const textbox = getByRole('combobox');
+ const listbox = getByRole('listbox');
fireEvent.keyDown(textbox, { key: 'ArrowDown' }); // goes to 'one'
fireEvent.keyDown(textbox, { key: 'ArrowDown' }); // goes to 'two'
@@ -1339,7 +1345,7 @@ describe('Joy
', () => {
});
it('should keep focus when multiple options are selected and not reset to top option when options updated', () => {
- const { setProps } = render(
+ const { setProps, getByRole } = render(
', () => {
autoFocus
/>,
);
- const textbox = screen.getByRole('combobox');
- const listbox = screen.getByRole('listbox');
+ const textbox = getByRole('combobox');
+ const listbox = getByRole('listbox');
fireEvent.keyDown(textbox, { key: 'ArrowDown' });
fireEvent.keyDown(textbox, { key: 'ArrowDown' });
@@ -1364,7 +1370,7 @@ describe('Joy
', () => {
it('should keep focus when multiple options are selected by not resetting to the top option when options are updated and when options are provided as objects', () => {
const value = [{ label: 'one' }];
const options = [{ label: 'one' }, { label: 'two' }, { label: 'three' }];
- const { setProps } = render(
+ const { setProps, getByRole } = render(
', () => {
open
/>,
);
- const textbox = screen.getByRole('combobox');
- const listbox = screen.getByRole('listbox');
+ const textbox = getByRole('combobox');
+ const listbox = getByRole('listbox');
fireEvent.keyDown(textbox, { key: 'ArrowDown' });
fireEvent.keyDown(textbox, { key: 'ArrowDown' });
@@ -1390,11 +1396,11 @@ describe('Joy
', () => {
});
it('should keep focus on selected option when options updates and when options are provided as objects', () => {
- const { setProps } = render(
+ const { setProps, getByRole } = render(
,
);
- const textbox = screen.getByRole('combobox');
- const listbox = screen.getByRole('listbox');
+ const textbox = getByRole('combobox');
+ const listbox = getByRole('listbox');
fireEvent.keyDown(textbox, { key: 'ArrowDown' }); // goes to 'one'
fireEvent.keyDown(textbox, { key: 'ArrowDown' }); // goes to 'two'
@@ -1413,9 +1419,11 @@ describe('Joy
', () => {
});
it("should reset the highlight when previously highlighted option doesn't exists in new options", () => {
- const { setProps } = render(
);
- const textbox = screen.getByRole('combobox');
- const listbox = screen.getByRole('listbox');
+ const { setProps, getByRole } = render(
+
,
+ );
+ const textbox = getByRole('combobox');
+ const listbox = getByRole('listbox');
fireEvent.keyDown(textbox, { key: 'ArrowDown' }); // goes to 'one'
fireEvent.keyDown(textbox, { key: 'ArrowDown' }); // goes to 'two'
@@ -1748,7 +1756,7 @@ describe('Joy
', () => {
it('should not delete exiting tag when try to add it twice', () => {
const handleChange = spy();
const options = ['one', 'two'];
- const { container } = render(
+ const { container, getByRole } = render(
', () => {
multiple
/>,
);
- const textbox = screen.getByRole('combobox');
+ const textbox = getByRole('combobox');
fireEvent.change(textbox, { target: { value: 'three' } });
fireEvent.keyDown(textbox, { key: 'Enter' });
@@ -1927,9 +1935,9 @@ describe('Joy
', () => {
);
}
- const { user } = render(
);
+ const { user, getByText } = render(
);
- await user.click(screen.getByText('Reset'));
+ await user.click(getByText('Reset'));
// eslint-disable-next-line no-nested-ternary
const expectedCallCount = reactMajor >= 19 ? 3 : reactMajor === 18 ? 4 : 2;
@@ -1942,7 +1950,7 @@ describe('Joy
', () => {
it('provides a reason on clear', async () => {
const handleInputChange = spy();
const options = [{ name: 'foo' }];
- const { user } = render(
+ const { user, getByLabelText } = render(
', () => {
/>,
);
- await user.click(screen.getByLabelText('Clear'));
+ await user.click(getByLabelText('Clear'));
expect(handleInputChange.lastCall.args[1]).to.equal('');
expect(handleInputChange.lastCall.args[2]).to.equal('clear');
@@ -1961,7 +1969,7 @@ describe('Joy
', () => {
it('provides a reason on blur', async () => {
const handleInputChange = spy();
const options = [{ name: 'foo' }];
- const { user } = render(
+ const { user, getByRole } = render(
', () => {
clearOnBlur
/>,
);
- await user.type(screen.getByRole('combobox'), options[0].name);
+ await user.type(getByRole('combobox'), options[0].name);
await user.tab();
expect(handleInputChange.lastCall.args[1]).to.equal('');
@@ -1980,7 +1988,7 @@ describe('Joy
', () => {
it('provides a reason on select option', async () => {
const handleInputChange = spy();
const options = [{ name: 'foo' }];
- const { user } = render(
+ const { user, getByLabelText, getByRole } = render(
', () => {
/>,
);
- await user.click(screen.getByLabelText('Open'));
- await user.click(screen.getByRole('option', { name: options[0].name }));
+ await user.click(getByLabelText('Open'));
+ await user.click(getByRole('option', { name: options[0].name }));
expect(handleInputChange.lastCall.args[1]).to.equal(options[0].name);
expect(handleInputChange.lastCall.args[2]).to.equal('selectOption');
@@ -1999,7 +2007,7 @@ describe('Joy
', () => {
it('provides a reason on remove option', async () => {
const handleInputChange = spy();
const options = [{ name: 'foo' }];
- const { user } = render(
+ const { user, getByRole } = render(
', () => {
/>,
);
- await user.type(screen.getByRole('combobox'), `${options[0].name}{Enter}`);
+ await user.type(getByRole('combobox'), `${options[0].name}{Enter}`);
expect(handleInputChange.lastCall.args[1]).to.equal('');
expect(handleInputChange.lastCall.args[2]).to.equal('removeOption');
@@ -2120,7 +2128,7 @@ describe('Joy
', () => {
});
it('should update the input value when getOptionLabel changes', () => {
- const { setProps } = render(
+ const { setProps, getByRole } = render(
', () => {
getOptionLabel={(option) => option}
/>,
);
- const textbox = screen.getByRole('combobox');
+ const textbox = getByRole('combobox');
expect(textbox).to.have.property('value', 'one');
setProps({
getOptionLabel: (option: string) => option.toUpperCase(),
@@ -2137,7 +2145,7 @@ describe('Joy
', () => {
});
it('should not update the input value when users is focusing', () => {
- const { setProps } = render(
+ const { setProps, getByRole } = render(
', () => {
autoFocus
/>,
);
- const textbox = screen.getByRole('combobox');
+ const textbox = getByRole('combobox');
expect(textbox).to.have.property('value', 'one');
fireEvent.change(textbox, { target: { value: 'a' } });
setProps({
@@ -2461,7 +2469,7 @@ describe('Joy
', () => {
});
it('should not be able to delete the tag when multiple=true', () => {
- const { container } = render(
+ const { container, getByRole } = render(
', () => {
/>,
);
- const textbox = screen.getByRole('combobox');
+ const textbox = getByRole('combobox');
act(() => {
textbox.focus();
});
diff --git a/packages/mui-joy/src/Box/Box.test.tsx b/packages/mui-joy/src/Box/Box.test.tsx
index 87644fe248ef20..286e4ecca53a80 100644
--- a/packages/mui-joy/src/Box/Box.test.tsx
+++ b/packages/mui-joy/src/Box/Box.test.tsx
@@ -28,7 +28,7 @@ describe('Joy
', () => {
}));
it('respects theme from context', function test() {
- const isJSDOM = /jsdom/.test(window.navigator.userAgent);
+ const isJSDOM = window.navigator.userAgent.includes('jsdom');
if (isJSDOM) {
this.skip();
@@ -93,7 +93,7 @@ describe('Joy
', () => {
});
it('color', function test() {
- const isJSDOM = /jsdom/.test(window.navigator.userAgent);
+ const isJSDOM = window.navigator.userAgent.includes('jsdom');
if (isJSDOM) {
this.skip();
@@ -111,7 +111,7 @@ describe('Joy
', () => {
});
it('bgcolor', function test() {
- const isJSDOM = /jsdom/.test(window.navigator.userAgent);
+ const isJSDOM = window.navigator.userAgent.includes('jsdom');
if (isJSDOM) {
this.skip();
@@ -129,7 +129,7 @@ describe('Joy
', () => {
});
it('backgroundColor', function test() {
- const isJSDOM = /jsdom/.test(window.navigator.userAgent);
+ const isJSDOM = window.navigator.userAgent.includes('jsdom');
if (isJSDOM) {
this.skip();
@@ -147,7 +147,7 @@ describe('Joy
', () => {
});
it('borderRadius', function test() {
- const isJSDOM = /jsdom/.test(window.navigator.userAgent);
+ const isJSDOM = window.navigator.userAgent.includes('jsdom');
if (isJSDOM) {
this.skip();
@@ -168,7 +168,7 @@ describe('Joy
', () => {
});
it('boxShadow', function test() {
- const isJSDOM = /jsdom/.test(window.navigator.userAgent);
+ const isJSDOM = window.navigator.userAgent.includes('jsdom');
if (isJSDOM) {
this.skip();
@@ -186,7 +186,7 @@ describe('Joy
', () => {
});
it('fontSize', function test() {
- const isJSDOM = /jsdom/.test(window.navigator.userAgent);
+ const isJSDOM = window.navigator.userAgent.includes('jsdom');
if (isJSDOM) {
this.skip();
@@ -204,7 +204,7 @@ describe('Joy
', () => {
});
it('fontWeight', function test() {
- const isJSDOM = /jsdom/.test(window.navigator.userAgent);
+ const isJSDOM = window.navigator.userAgent.includes('jsdom');
if (isJSDOM) {
this.skip();
@@ -222,7 +222,7 @@ describe('Joy
', () => {
});
it('lineHeight', function test() {
- const isJSDOM = /jsdom/.test(window.navigator.userAgent);
+ const isJSDOM = window.navigator.userAgent.includes('jsdom');
if (isJSDOM) {
this.skip();
diff --git a/packages/mui-joy/src/Button/Button.test.tsx b/packages/mui-joy/src/Button/Button.test.tsx
index 47e10fce89fec8..208313d30c8598 100644
--- a/packages/mui-joy/src/Button/Button.test.tsx
+++ b/packages/mui-joy/src/Button/Button.test.tsx
@@ -137,7 +137,7 @@ describe('Joy
', () => {
describe('prop:disabled', () => {
it('should apply disabled styles when button is disabled', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
const { getByRole } = render(
);
@@ -149,7 +149,7 @@ describe('Joy
', () => {
});
it('should apply disabled styles when button is disabled and when component prop is provided', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
const { getByRole } = render(
);
@@ -169,7 +169,7 @@ describe('Joy
', () => {
});
it('is rendered properly when `loading` and children should not be visible', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
const { container, getByRole } = render(
diff --git a/packages/mui-joy/src/CssBaseline/CssBaseline.test.tsx b/packages/mui-joy/src/CssBaseline/CssBaseline.test.tsx
index ee4567edd3934e..78987012028674 100644
--- a/packages/mui-joy/src/CssBaseline/CssBaseline.test.tsx
+++ b/packages/mui-joy/src/CssBaseline/CssBaseline.test.tsx
@@ -1 +1,3 @@
-describe('
', () => {});
+describe('
', () => {
+ it('To do', () => {});
+});
diff --git a/packages/mui-joy/src/Drawer/Drawer.test.tsx b/packages/mui-joy/src/Drawer/Drawer.test.tsx
index 88a8ca931d965a..792538e541783a 100644
--- a/packages/mui-joy/src/Drawer/Drawer.test.tsx
+++ b/packages/mui-joy/src/Drawer/Drawer.test.tsx
@@ -67,7 +67,7 @@ describe('
', () => {
});
it('should apply content theme styles for content slot', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
diff --git a/packages/mui-joy/src/Link/Link.test.tsx b/packages/mui-joy/src/Link/Link.test.tsx
index 0da69c7a560910..e13ae12350e68a 100644
--- a/packages/mui-joy/src/Link/Link.test.tsx
+++ b/packages/mui-joy/src/Link/Link.test.tsx
@@ -76,7 +76,7 @@ describe('
', () => {
describe('keyboard focus', () => {
it('should add the focusVisible class when focused', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
// JSDOM doesn't support :focus-visible
this.skip();
}
diff --git a/packages/mui-joy/src/ListDivider/ListDivider.test.tsx b/packages/mui-joy/src/ListDivider/ListDivider.test.tsx
index eaba1068e18869..1e57e67d76e666 100644
--- a/packages/mui-joy/src/ListDivider/ListDivider.test.tsx
+++ b/packages/mui-joy/src/ListDivider/ListDivider.test.tsx
@@ -79,13 +79,13 @@ describe('Joy
', () => {
});
it('should be `div` if `List` is not one of `ol, ul, menu`', () => {
- const { container } = render(
+ const view = render(
,
);
expect(screen.queryByRole('separator')).to.equal(null);
- expect(container.firstChild?.firstChild).to.have.tagName('div');
+ expect(view.container.firstChild?.firstChild).to.have.tagName('div');
});
});
});
diff --git a/packages/mui-joy/src/ListItem/ListItem.test.tsx b/packages/mui-joy/src/ListItem/ListItem.test.tsx
index 3c8ae0423c0ddc..d1aaf84455d66a 100644
--- a/packages/mui-joy/src/ListItem/ListItem.test.tsx
+++ b/packages/mui-joy/src/ListItem/ListItem.test.tsx
@@ -101,7 +101,7 @@ describe('Joy
', () => {
describe('Semantics - List', () => {
it('should render div automatically if parent List component is not `ol`, `ul`, `menu`', () => {
- const { getByRole, getAllByRole } = render(
+ render(
item 1
@@ -118,8 +118,8 @@ describe('Joy ', () => {
,
);
- expect(getByRole('group').firstChild).to.have.tagName('DIV');
- const lists = getAllByRole('list');
+ expect(screen.getByRole('group').firstChild).to.have.tagName('DIV');
+ const lists = screen.getAllByRole('list');
lists.forEach((list) => {
expect(list.firstChild).to.have.tagName('LI');
});
diff --git a/packages/mui-joy/src/ListItemButton/ListItemButton.test.tsx b/packages/mui-joy/src/ListItemButton/ListItemButton.test.tsx
index 08f3eb26a2c20d..6fe60ccc363c3e 100644
--- a/packages/mui-joy/src/ListItemButton/ListItemButton.test.tsx
+++ b/packages/mui-joy/src/ListItemButton/ListItemButton.test.tsx
@@ -57,7 +57,7 @@ describe('Joy
', () => {
describe('prop: focusVisibleClassName', () => {
it('should have focusVisible classes', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
// JSDOM doesn't support :focus-visible
this.skip();
}
diff --git a/packages/mui-joy/src/Modal/Modal.test.tsx b/packages/mui-joy/src/Modal/Modal.test.tsx
index 493c15a92f6b32..173226d7d80f56 100644
--- a/packages/mui-joy/src/Modal/Modal.test.tsx
+++ b/packages/mui-joy/src/Modal/Modal.test.tsx
@@ -358,7 +358,7 @@ describe('
', () => {
clock.withFakeTimers();
it('does not steal focus from other frames', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
// TODO: Unclear why this fails. Not important
// since a browser test gives us more confidence anyway
this.skip();
diff --git a/packages/mui-joy/src/Option/Option.test.tsx b/packages/mui-joy/src/Option/Option.test.tsx
index 518126eb8be5c0..df2d9988113e6b 100644
--- a/packages/mui-joy/src/Option/Option.test.tsx
+++ b/packages/mui-joy/src/Option/Option.test.tsx
@@ -1 +1,3 @@
-describe('
', () => {});
+describe('
', () => {
+ it('To do', () => {});
+});
diff --git a/packages/mui-joy/src/Select/Select.test.tsx b/packages/mui-joy/src/Select/Select.test.tsx
index bfe89587c6bdbf..a6d86d58074505 100644
--- a/packages/mui-joy/src/Select/Select.test.tsx
+++ b/packages/mui-joy/src/Select/Select.test.tsx
@@ -497,7 +497,7 @@ describe('Joy
', () => {
describe('form submission', () => {
it('includes the Select value in the submitted form data when the `name` attribute is provided', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
// FormData is not available in JSDOM
this.skip();
}
@@ -530,7 +530,7 @@ describe('Joy
', () => {
});
it('transforms the selected value before posting using the getSerializedValue prop, if provided', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
// FormData is not available in JSDOM
this.skip();
}
@@ -566,7 +566,7 @@ describe('Joy
', () => {
});
it('formats the object values as JSON before posting', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
// FormData is not available in JSDOM
this.skip();
}
diff --git a/packages/mui-joy/src/SvgIcon/SvgIcon.test.tsx b/packages/mui-joy/src/SvgIcon/SvgIcon.test.tsx
index 2b6ee0b27db6bc..2885221eba25aa 100644
--- a/packages/mui-joy/src/SvgIcon/SvgIcon.test.tsx
+++ b/packages/mui-joy/src/SvgIcon/SvgIcon.test.tsx
@@ -151,7 +151,7 @@ describe('
', () => {
});
it('should not override internal ownerState with the ownerState passed to the icon', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
@@ -163,7 +163,7 @@ describe('
', () => {
});
it('should have `fill="currentColor"`', function test() {
- if (!/jsdom/.test(window.navigator.userAgent)) {
+ if (!window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
const { container } = render(
@@ -176,7 +176,7 @@ describe('
', () => {
});
it('should not add `fill` if svg is a direct child', function test() {
- if (!/jsdom/.test(window.navigator.userAgent)) {
+ if (!window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
const { container } = render(
diff --git a/packages/mui-joy/src/Switch/Switch.test.tsx b/packages/mui-joy/src/Switch/Switch.test.tsx
index d14a52403e2db0..50e04f50b4cbe1 100644
--- a/packages/mui-joy/src/Switch/Switch.test.tsx
+++ b/packages/mui-joy/src/Switch/Switch.test.tsx
@@ -35,7 +35,7 @@ describe('
', () => {
}));
it('should pass `slotProps` down to slots', () => {
- const { container } = render(
+ const view = render(
', () => {
);
expect(screen.getByTestId('root-switch')).toBeVisible();
- expect(container.querySelector('.custom-thumb')).to.have.class(classes.thumb);
- expect(container.querySelector('.custom-track')).to.have.class(classes.track);
- expect(container.querySelector('.custom-action')).to.have.class(classes.action);
- expect(container.querySelector('.custom-input')).to.have.class(classes.input);
+ expect(view.container.querySelector('.custom-thumb')).to.have.class(classes.thumb);
+ expect(view.container.querySelector('.custom-track')).to.have.class(classes.track);
+ expect(view.container.querySelector('.custom-action')).to.have.class(classes.action);
+ expect(view.container.querySelector('.custom-input')).to.have.class(classes.input);
});
it('should have the classes required for Switch', () => {
diff --git a/packages/mui-joy/src/Typography/Typography.test.tsx b/packages/mui-joy/src/Typography/Typography.test.tsx
index 8bf2616d5f177a..9f4e4538d1b44c 100644
--- a/packages/mui-joy/src/Typography/Typography.test.tsx
+++ b/packages/mui-joy/src/Typography/Typography.test.tsx
@@ -99,7 +99,7 @@ describe('
', () => {
});
it('combines system properties with the sx prop', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
const { container } = render(
);
diff --git a/packages/mui-joy/src/styles/CssVarsProvider.test.tsx b/packages/mui-joy/src/styles/CssVarsProvider.test.tsx
index 9bb17ff8964bce..9964ec20949eeb 100644
--- a/packages/mui-joy/src/styles/CssVarsProvider.test.tsx
+++ b/packages/mui-joy/src/styles/CssVarsProvider.test.tsx
@@ -11,7 +11,7 @@ describe('[Joy] CssVarsProvider', () => {
beforeEach(() => {
originalMatchmedia = window.matchMedia;
// Create mocks of localStorage getItem and setItem functions
- Object.defineProperty(global, 'localStorage', {
+ Object.defineProperty(globalThis, 'localStorage', {
value: {
getItem: (key: string) => storage[key],
setItem: (key: string, value: string) => {
diff --git a/packages/mui-joy/src/styles/extendTheme.test.js b/packages/mui-joy/src/styles/extendTheme.test.js
index 9bf3097075bac3..aa2b1b96e00397 100644
--- a/packages/mui-joy/src/styles/extendTheme.test.js
+++ b/packages/mui-joy/src/styles/extendTheme.test.js
@@ -205,7 +205,7 @@ describe('extendTheme', () => {
beforeEach(() => {
originalMatchmedia = window.matchMedia;
// Create mocks of localStorage getItem and setItem functions
- Object.defineProperty(global, 'localStorage', {
+ Object.defineProperty(globalThis, 'localStorage', {
value: {
getItem: (key) => storage[key],
setItem: (key, value) => {
diff --git a/packages/mui-joy/src/styles/styled.test.tsx b/packages/mui-joy/src/styles/styled.test.tsx
index db726b2913d10e..18eadd3bc469c9 100644
--- a/packages/mui-joy/src/styles/styled.test.tsx
+++ b/packages/mui-joy/src/styles/styled.test.tsx
@@ -10,7 +10,7 @@ describe('[Joy] styled', () => {
const { render } = createRenderer();
it('use defaultTheme given no ThemeProvider', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
const Text = styled('div')(({ theme }) => ({
@@ -28,7 +28,7 @@ describe('[Joy] styled', () => {
});
it('use theme from ThemeProvider', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
const Text = styled('div')(({ theme }) => ({
@@ -50,7 +50,7 @@ describe('[Joy] styled', () => {
});
it('supports unstable_sx in the theme callback', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
const customTheme = extendTheme({
diff --git a/packages/mui-lab/src/AlertTitle/AlertTitle.test.js b/packages/mui-lab/src/AlertTitle/AlertTitle.test.js
new file mode 100644
index 00000000000000..38c6a71e4cbd91
--- /dev/null
+++ b/packages/mui-lab/src/AlertTitle/AlertTitle.test.js
@@ -0,0 +1,3 @@
+describe('
', () => {
+ it('To do', () => {});
+});
diff --git a/packages/mui-lab/src/Masonry/Masonry.test.js b/packages/mui-lab/src/Masonry/Masonry.test.js
index d79510cbdd3d02..5aa9be584c8b1d 100644
--- a/packages/mui-lab/src/Masonry/Masonry.test.js
+++ b/packages/mui-lab/src/Masonry/Masonry.test.js
@@ -1,5 +1,5 @@
import * as React from 'react';
-import { createRenderer, reactMajor } from '@mui/internal-test-utils';
+import { createRenderer, reactMajor, act } from '@mui/internal-test-utils';
import { expect } from 'chai';
import { createTheme } from '@mui/material/styles';
import defaultTheme from '@mui/material/styles/defaultTheme';
@@ -30,7 +30,7 @@ describe('
', () => {
describe('render', () => {
it('should render with correct default styles', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
const width = 400;
@@ -68,7 +68,7 @@ describe('
', () => {
});
it('should re-compute the height of masonry when dimensions of any child change', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
// only run on browser
this.skip();
}
@@ -101,7 +101,7 @@ describe('
', () => {
it('should throw console error when children are empty', function test() {
// React 19 removed prop types support
- if (!/jsdom/.test(window.navigator.userAgent) || reactMajor >= 19) {
+ if (!window.navigator.userAgent.includes('jsdom') || reactMajor >= 19) {
this.skip();
}
expect(() => render(
)).toErrorDev(
@@ -110,7 +110,7 @@ describe('
', () => {
});
it('should not throw type error when children are empty', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
@@ -379,14 +379,17 @@ describe('
', () => {
describe('prop: sequential', () => {
const pause = (timeout) =>
- new Promise((resolve) => {
- setTimeout(() => {
- resolve();
- }, timeout);
- });
+ act(
+ async () =>
+ new Promise((resolve) => {
+ setTimeout(() => {
+ resolve();
+ }, timeout);
+ }),
+ );
it('should place children in sequential order', async function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
// only run on browser
this.skip();
}
diff --git a/packages/mui-material/src/Accordion/Accordion.test.js b/packages/mui-material/src/Accordion/Accordion.test.js
index 8296fe83555c14..5cf97d252ce9c4 100644
--- a/packages/mui-material/src/Accordion/Accordion.test.js
+++ b/packages/mui-material/src/Accordion/Accordion.test.js
@@ -11,6 +11,7 @@ import Slide from '@mui/material/Slide';
import Grow from '@mui/material/Grow';
import Zoom from '@mui/material/Zoom';
import AccordionSummary from '@mui/material/AccordionSummary';
+import describeSkipIf from '@mui/internal-test-utils/describeSkipIf';
import describeConformance from '../../test/describeConformance';
function NoTransition(props) {
@@ -172,13 +173,8 @@ describe('
', () => {
});
describe('prop: children', () => {
- describe('first child', () => {
- beforeEach(function beforeEachCallback() {
- if (reactMajor >= 19) {
- // React 19 removed prop types support
- this.skip();
- }
-
+ describeSkipIf(reactMajor >= 19)('first child', () => {
+ beforeEach(() => {
PropTypes.resetWarningCache();
});
diff --git a/packages/mui-material/src/AccordionActions/AccordionActions.test.js b/packages/mui-material/src/AccordionActions/AccordionActions.test.js
index 0ce0b4e300a52b..4b23105265d4f9 100644
--- a/packages/mui-material/src/AccordionActions/AccordionActions.test.js
+++ b/packages/mui-material/src/AccordionActions/AccordionActions.test.js
@@ -21,7 +21,7 @@ describe('
', () => {
}));
it('should apply margin to all children but the first one', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
diff --git a/packages/mui-material/src/AccordionSummary/AccordionSummary.test.js b/packages/mui-material/src/AccordionSummary/AccordionSummary.test.js
index f0279b38dd8ee4..dc6ec70a64d1a9 100644
--- a/packages/mui-material/src/AccordionSummary/AccordionSummary.test.js
+++ b/packages/mui-material/src/AccordionSummary/AccordionSummary.test.js
@@ -115,7 +115,7 @@ describe('
', () => {
});
it('calls onFocusVisible if focused visibly', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
// JSDOM doesn't support :focus-visible
this.skip();
}
diff --git a/packages/mui-material/src/AppBar/AppBar.test.js b/packages/mui-material/src/AppBar/AppBar.test.js
index 6319ef4b5f7a6a..f36965d3039d6d 100644
--- a/packages/mui-material/src/AppBar/AppBar.test.js
+++ b/packages/mui-material/src/AppBar/AppBar.test.js
@@ -66,7 +66,7 @@ describe('
', () => {
});
it('should inherit Paper background color with ThemeProvider', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
@@ -85,7 +85,7 @@ describe('
', () => {
});
it('should inherit Paper background color with CssVarsProvider', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
diff --git a/packages/mui-material/src/Autocomplete/Autocomplete.test.js b/packages/mui-material/src/Autocomplete/Autocomplete.test.js
index 69da2763fc264f..2de65dfcf3ef30 100644
--- a/packages/mui-material/src/Autocomplete/Autocomplete.test.js
+++ b/packages/mui-material/src/Autocomplete/Autocomplete.test.js
@@ -158,10 +158,8 @@ describe('
', () => {
describe('combobox', () => {
it('should clear the input when blur', () => {
- const { getByRole } = render(
-
} />,
- );
- const input = getByRole('combobox');
+ render( } />);
+ const input = screen.getByRole('combobox');
act(() => {
input.focus();
@@ -177,15 +175,15 @@ describe('', () => {
});
it('should apply the icon classes', () => {
- const { container } = render(
+ const view = render(
}
/>,
);
- expect(container.querySelector(`.${classes.root}`)).to.have.class(classes.hasClearIcon);
- expect(container.querySelector(`.${classes.root}`)).to.have.class(classes.hasPopupIcon);
+ expect(view.container.querySelector(`.${classes.root}`)).to.have.class(classes.hasClearIcon);
+ expect(view.container.querySelector(`.${classes.root}`)).to.have.class(classes.hasPopupIcon);
});
});
@@ -224,7 +222,7 @@ describe('', () => {
describe('prop: autoHighlight', () => {
it('should set the focus on the first item', () => {
const options = ['one', 'two'];
- const { getByRole } = render(
+ render(
', () => {
/>,
);
- checkHighlightIs(getByRole('listbox'), 'one');
+ checkHighlightIs(screen.getByRole('listbox'), 'one');
fireEvent.change(document.activeElement, { target: { value: 'oo' } });
fireEvent.change(document.activeElement, { target: { value: 'o' } });
- checkHighlightIs(getByRole('listbox'), 'one');
+ checkHighlightIs(screen.getByRole('listbox'), 'one');
});
it('should keep the highlight on the first item', () => {
const options = ['one', 'two'];
- const { getByRole } = render(
+ render(
', () => {
/>,
);
- checkHighlightIs(getByRole('listbox'), 'one');
+ checkHighlightIs(screen.getByRole('listbox'), 'one');
fireEvent.change(document.activeElement, { target: { value: 'two' } });
- checkHighlightIs(getByRole('listbox'), 'two');
+ checkHighlightIs(screen.getByRole('listbox'), 'two');
});
it('should set the focus on the first item when possible', () => {
const options = ['one', 'two'];
- const { getByRole, setProps } = render(
+ const view = render(
', () => {
renderInput={(params) => }
/>,
);
- const textbox = getByRole('combobox');
+ const textbox = screen.getByRole('combobox');
expect(textbox).not.to.have.attribute('aria-activedescendant');
- setProps({ options, loading: false });
+ view.setProps({ options, loading: false });
expect(textbox).to.have.attribute(
'aria-activedescendant',
screen.getAllByRole('option')[0].getAttribute('id'),
@@ -279,7 +277,7 @@ describe('', () => {
});
it('should set the highlight on selected item when dropdown is expanded', () => {
- const { getByRole, setProps } = render(
+ const view = render(
', () => {
/>,
);
- checkHighlightIs(getByRole('listbox'), 'one');
- setProps({ value: 'two' });
- checkHighlightIs(getByRole('listbox'), 'two');
+ checkHighlightIs(screen.getByRole('listbox'), 'one');
+ view.setProps({ value: 'two' });
+ checkHighlightIs(screen.getByRole('listbox'), 'two');
});
// https://github.com/mui/material-ui/issues/34998
it('should scroll the listbox to the top when keyboard highlight wraps around after the last item is highlighted', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
this.skip();
}
- const { getByRole } = render(
+ render(
', () => {
}}
/>,
);
- const textbox = getByRole('combobox');
+ const textbox = screen.getByRole('combobox');
act(() => {
textbox.focus();
});
@@ -322,12 +320,12 @@ describe('', () => {
fireEvent.keyDown(textbox, { key: 'ArrowDown' });
fireEvent.keyDown(textbox, { key: 'ArrowDown' });
- checkHighlightIs(getByRole('listbox'), 'one');
- expect(getByRole('listbox')).to.have.property('scrollTop', 0);
+ checkHighlightIs(screen.getByRole('listbox'), 'one');
+ expect(screen.getByRole('listbox')).to.have.property('scrollTop', 0);
});
it('should keep the current highlight if possible', () => {
- const { getByRole } = render(
+ render(
', () => {
renderInput={(params) => }
/>,
);
- const textbox = getByRole('combobox');
+ const textbox = screen.getByRole('combobox');
- checkHighlightIs(getByRole('listbox'), 'one');
+ checkHighlightIs(screen.getByRole('listbox'), 'one');
fireEvent.keyDown(textbox, { key: 'ArrowDown' });
- checkHighlightIs(getByRole('listbox'), 'two');
+ checkHighlightIs(screen.getByRole('listbox'), 'two');
fireEvent.keyDown(textbox, { key: 'Enter' });
- checkHighlightIs(getByRole('listbox'), 'two');
+ checkHighlightIs(screen.getByRole('listbox'), 'two');
});
it('should work with filterSelectedOptions too', () => {
const options = ['Foo', 'Bar', 'Baz'];
- const { getByRole } = render(
+ render(
', () => {
renderInput={(params) => }
/>,
);
- const textbox = getByRole('combobox');
+ const textbox = screen.getByRole('combobox');
fireEvent.keyDown(textbox, { key: 'ArrowDown' });
- checkHighlightIs(getByRole('listbox'), 'Bar');
+ checkHighlightIs(screen.getByRole('listbox'), 'Bar');
fireEvent.change(textbox, { target: { value: 'a' } });
- checkHighlightIs(getByRole('listbox'), 'Bar');
+ checkHighlightIs(screen.getByRole('listbox'), 'Bar');
fireEvent.change(textbox, { target: { value: 'aa' } });
fireEvent.change(textbox, { target: { value: 'a' } });
- checkHighlightIs(getByRole('listbox'), 'Bar');
+ checkHighlightIs(screen.getByRole('listbox'), 'Bar');
});
// https://github.com/mui/material-ui/issues/45279
it('should auto highlight first option after options order changes with autoHighlight', () => {
- const { setProps, getByRole } = render(
+ const view = render(
', () => {
/>,
);
- checkHighlightIs(getByRole('listbox'), 'pediatric ent');
- setProps({
+ checkHighlightIs(screen.getByRole('listbox'), 'pediatric ent');
+ view.setProps({
options: ['pediatrician', 'pediatric ent', 'pediatric flu', 'pediatric cough'],
});
- checkHighlightIs(getByRole('listbox'), 'pediatrician');
+ checkHighlightIs(screen.getByRole('listbox'), 'pediatrician');
});
it('should auto highlight first option when no match with input value with autoHighlight', () => {
- const { getByRole } = render(
+ render(
', () => {
/>,
);
- checkHighlightIs(getByRole('listbox'), '1');
+ checkHighlightIs(screen.getByRole('listbox'), '1');
});
it('should auto highlight first option of rest after selecting an option with autoHighlight and filterSelectedOptions', () => {
- const { getByRole } = render(
+ render(
', () => {
/>,
);
- const textbox = getByRole('combobox');
+ const textbox = screen.getByRole('combobox');
- checkHighlightIs(getByRole('listbox'), '1');
+ checkHighlightIs(screen.getByRole('listbox'), '1');
fireEvent.keyDown(textbox, { key: 'Enter' });
- checkHighlightIs(getByRole('listbox'), '2');
+ checkHighlightIs(screen.getByRole('listbox'), '2');
});
});
describe('highlight synchronisation', () => {
it('should not update the highlight when multiple open and value change', () => {
- const { setProps, getByRole } = render(
+ const view = render(
', () => {
/>,
);
- checkHighlightIs(getByRole('listbox'), 'two');
- setProps({
+ checkHighlightIs(screen.getByRole('listbox'), 'two');
+ view.setProps({
value: [],
});
- checkHighlightIs(getByRole('listbox'), 'two');
+ checkHighlightIs(screen.getByRole('listbox'), 'two');
});
});
describe('prop: limitTags', () => {
it('show all items on focus', () => {
- const { container, getAllByRole, getByRole } = render(
+ const view = render(
', () => {
/>,
);
- expect(container.textContent).to.equal('onetwo+1');
+ expect(view.container.textContent).to.equal('onetwo+1');
// include hidden clear button because JSDOM thinks it's visible
- expect(getAllByRole('button', { hidden: true })).to.have.lengthOf(4);
+ expect(screen.getAllByRole('button', { hidden: true })).to.have.lengthOf(4);
act(() => {
- getByRole('combobox').focus();
+ screen.getByRole('combobox').focus();
});
- expect(container.textContent).to.equal('onetwothree');
+ expect(view.container.textContent).to.equal('onetwothree');
// Depending on the subset of components used in this test run the computed `visibility` changes in JSDOM.
- if (!/jsdom/.test(window.navigator.userAgent)) {
- expect(getAllByRole('button', { hidden: false })).to.have.lengthOf(5);
+ if (!window.navigator.userAgent.includes('jsdom')) {
+ expect(screen.getAllByRole('button', { hidden: false })).to.have.lengthOf(5);
}
});
it('show 0 item on close when set 0 to limitTags', () => {
- const { container, getAllByRole, getByRole } = render(
+ const view = render(
', () => {
/>,
);
- expect(container.textContent).to.equal('+3');
+ expect(view.container.textContent).to.equal('+3');
// include hidden clear button because JSDOM thinks it's visible
- expect(getAllByRole('button', { hidden: true })).to.have.lengthOf(2);
+ expect(screen.getAllByRole('button', { hidden: true })).to.have.lengthOf(2);
act(() => {
- getByRole('combobox').focus();
+ screen.getByRole('combobox').focus();
});
- expect(container.textContent).to.equal('onetwothree');
+ expect(view.container.textContent).to.equal('onetwothree');
// Depending on the subset of components used in this test run the computed `visibility` changes in JSDOM.
- if (!/jsdom/.test(window.navigator.userAgent)) {
- expect(getAllByRole('button', { hidden: false })).to.have.lengthOf(5);
+ if (!window.navigator.userAgent.includes('jsdom')) {
+ expect(screen.getAllByRole('button', { hidden: false })).to.have.lengthOf(5);
}
});
});
describe('prop: filterSelectedOptions', () => {
it('when the last item is selected, highlights the new last item', () => {
- const { getByRole } = render(
+ render(
', () => {
renderInput={(params) => }
/>,
);
- const textbox = getByRole('combobox');
+ const textbox = screen.getByRole('combobox');
fireEvent.keyDown(textbox, { key: 'ArrowUp' });
- checkHighlightIs(getByRole('listbox'), 'three');
+ checkHighlightIs(screen.getByRole('listbox'), 'three');
fireEvent.keyDown(textbox, { key: 'Enter' }); // selects the last option (three)
act(() => {
textbox.blur();
textbox.focus(); // opens the listbox again
});
- checkHighlightIs(getByRole('listbox'), null);
+ checkHighlightIs(screen.getByRole('listbox'), null);
});
});
@@ -594,7 +592,7 @@ describe('', () => {
describe('prop: multiple', () => {
it('should not crash', () => {
- const { getByRole } = render(
+ render(
', () => {
multiple
/>,
);
- const input = getByRole('combobox');
+ const input = screen.getByRole('combobox');
act(() => {
input.focus();
@@ -614,7 +612,7 @@ describe('', () => {
it('should remove the last option', () => {
const handleChange = spy();
const options = ['one', 'two'];
- const { getAllByTestId } = render(
+ render(
', () => {
multiple
/>,
);
- fireEvent.click(getAllByTestId('CancelIcon')[1]);
+ fireEvent.click(screen.getAllByTestId('CancelIcon')[1]);
expect(handleChange.callCount).to.equal(1);
expect(handleChange.args[0][1]).to.deep.equal([options[0]]);
});
@@ -694,7 +692,7 @@ describe('', () => {
it('should keep listbox open on pressing left or right keys when inputValue is not empty', () => {
const handleClose = spy();
const options = ['one', 'two', 'three'];
- const { getByRole } = render(
+ render(
', () => {
/>,
);
- const textbox = getByRole('combobox');
+ const textbox = screen.getByRole('combobox');
fireEvent.mouseDown(textbox);
fireEvent.keyDown(textbox, { key: 'ArrowLeft' });
@@ -716,7 +714,7 @@ describe('', () => {
it('should close listbox on pressing left or right keys when inputValue is empty', () => {
const handleClose = spy();
const options = ['one', 'two', 'three'];
- const { getByRole } = render(
+ render(
', () => {
/>,
);
- const textbox = getByRole('combobox');
+ const textbox = screen.getByRole('combobox');
fireEvent.mouseDown(textbox);
fireEvent.keyDown(textbox, { key: 'ArrowLeft' });
@@ -804,14 +802,14 @@ describe('', () => {
expect(screen.getByRole('combobox')).to.have.property('value', '');
});
- it('should fail validation if a required field has no value', function test() {
- if (/jsdom/.test(window.navigator.userAgent)) {
+ it('should fail validation if a required field has no value', async function test() {
+ if (window.navigator.userAgent.includes('jsdom')) {
// Enable once https://github.com/jsdom/jsdom/issues/2898 is resolved
this.skip();
}
const handleSubmit = spy((event) => event.preventDefault());
- render(
+ const view = render(
,
);
- screen.getByRole('button', { name: 'Submit' }).click();
+ await view.user.click(screen.getByRole('button', { name: 'Submit' }));
expect(handleSubmit.callCount).to.equal(0);
});
- it('should fail validation if a required field has a value', function test() {
+ it('should fail validation if a required field has a value', async function test() {
// Unclear how native Constraint validation can be enabled for `multiple`
- if (/jsdom/.test(window.navigator.userAgent)) {
+ if (window.navigator.userAgent.includes('jsdom')) {
// Enable once https://github.com/jsdom/jsdom/issues/2898 is resolved
// The test is passing in JSDOM but form validation is buggy in JSDOM so we rather skip than have false confidence
this.skip();
}
const handleSubmit = spy((event) => event.preventDefault());
- render(
+ const view = render(
,
);
- screen.getByRole('button', { name: 'Submit' }).click();
+ await view.user.click(screen.getByRole('button', { name: 'Submit' }));
expect(handleSubmit.callCount).to.equal(0);
});
@@ -876,7 +874,7 @@ describe('', () => {
);
}
- const { setProps } = render(