Skip to content

Commit 33a65cf

Browse files
authored
[test] Update test to consider unsuppressed double render logs in React 18 (#28068)
1 parent a70ea40 commit 33a65cf

File tree

15 files changed

+113
-54
lines changed

15 files changed

+113
-54
lines changed

packages/material-ui-private-theming/src/ThemeProvider/ThemeProvider.test.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { expect } from 'chai';
3-
import { createClientRender, RenderCounter } from 'test/utils';
3+
import { createClientRender, RenderCounter, strictModeDoubleLoggingSupressed } from 'test/utils';
44
import useTheme from '../useTheme';
55
import ThemeProvider from './ThemeProvider';
66

@@ -94,9 +94,7 @@ describe('ThemeProvider', () => {
9494
);
9595
}).toErrorDev([
9696
'However, no outer theme is present.',
97-
React.version.startsWith('16') &&
98-
// strict mode renders twice
99-
'However, no outer theme is present.',
97+
!strictModeDoubleLoggingSupressed && 'However, no outer theme is present.',
10098
]);
10199
});
102100

@@ -112,8 +110,7 @@ describe('ThemeProvider', () => {
112110
);
113111
}).toErrorDev([
114112
'Material-UI: You should return an object from your theme function',
115-
React.version.startsWith('16') &&
116-
// strict mode renders twice
113+
!strictModeDoubleLoggingSupressed &&
117114
'Material-UI: You should return an object from your theme function',
118115
]);
119116
});

packages/material-ui-styles/src/StylesProvider/StylesProvider.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import ReactDOMServer from 'react-dom/server';
33
import { expect } from 'chai';
44
import { create, SheetsRegistry } from 'jss';
5-
import { createMount } from 'test/utils';
5+
import { createMount, strictModeDoubleLoggingSupressed } from 'test/utils';
66
import StylesProvider, { StylesContext } from './StylesProvider';
77
import makeStyles from '../makeStyles';
88
import createGenerateClassName from '../createGenerateClassName';
@@ -146,7 +146,11 @@ describe('StylesProvider', () => {
146146
<Test />
147147
</StylesProvider>,
148148
);
149-
}).toErrorDev('Material-UI: You cannot use the jss and injectFirst props at the same time');
149+
}).toErrorDev([
150+
'Material-UI: You cannot use the jss and injectFirst props at the same time',
151+
!strictModeDoubleLoggingSupressed &&
152+
'Material-UI: You cannot use the jss and injectFirst props at the same time',
153+
]);
150154
});
151155
});
152156
});

packages/material-ui-styles/src/useThemeVariants/useThemeVariants.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai';
22
import * as React from 'react';
3-
import { createClientRender, screen } from 'test/utils';
3+
import { createClientRender, screen, strictModeDoubleLoggingSupressed } from 'test/utils';
44
import { createTheme } from '@mui/material/styles';
55
import ThemeProvider from '../ThemeProvider';
66
import useThemeVariants from './useThemeVariants';
@@ -139,8 +139,7 @@ describe('useThemeVariants', () => {
139139
`Material-UI: You are using a variant value \`test\` for which you didn't define styles.`,
140140
`Please create a new variant matcher in your theme for this variant. To learn more about matchers visit https://next.material-ui.com/r/custom-component-variants.`,
141141
].join('\n'),
142-
React.version.startsWith('16') &&
143-
// strict mode renders twice
142+
!strictModeDoubleLoggingSupressed &&
144143
[
145144
`Material-UI: You are using a variant value \`test\` for which you didn't define styles.`,
146145
`Please create a new variant matcher in your theme for this variant. To learn more about matchers visit https://next.material-ui.com/r/custom-component-variants.`,

packages/material-ui-unstyled/src/AutocompleteUnstyled/useAutocomplete.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,10 @@ describe('useAutocomplete', () => {
263263
React.version.startsWith('18') &&
264264
"Error: Uncaught [TypeError: Cannot read property 'removeAttribute' of null]",
265265
'The above error occurred in the <ul> component',
266-
// strict mode renders twice
267266
React.version.startsWith('16') && 'The above error occurred in the <ul> component',
268267
'The above error occurred in the <Test> component',
269268
// strict effects runs effects twice
270269
React.version.startsWith('18') && 'The above error occurred in the <Test> component',
271-
// strict mode renders twice
272270
React.version.startsWith('16') && 'The above error occurred in the <Test> component',
273271
];
274272

packages/material-ui/src/Autocomplete/Autocomplete.test.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import * as React from 'react';
22
import PropTypes from 'prop-types';
33
import { expect } from 'chai';
4-
import { describeConformance, act, createClientRender, fireEvent, screen } from 'test/utils';
4+
import {
5+
describeConformance,
6+
act,
7+
createClientRender,
8+
fireEvent,
9+
screen,
10+
strictModeDoubleLoggingSupressed,
11+
} from 'test/utils';
512
import { spy } from 'sinon';
613
import { ThemeProvider, createTheme } from '@mui/material/styles';
714
import TextField from '@mui/material/TextField';
@@ -1231,11 +1238,9 @@ describe('<Autocomplete />', () => {
12311238
fireEvent.keyDown(textbox, { key: 'Enter' });
12321239
}).toErrorDev([
12331240
'Material-UI: The `getOptionLabel` method of Autocomplete returned undefined instead of a string',
1234-
// strict mode renders twice
1235-
React.version.startsWith('16') &&
1241+
!strictModeDoubleLoggingSupressed &&
12361242
'Material-UI: The `getOptionLabel` method of Autocomplete returned undefined instead of a string',
1237-
// strict mode renders twice
1238-
React.version.startsWith('16') &&
1243+
!strictModeDoubleLoggingSupressed &&
12391244
'Material-UI: The `getOptionLabel` method of Autocomplete returned undefined instead of a string',
12401245
'Material-UI: The `getOptionLabel` method of Autocomplete returned undefined instead of a string',
12411246
'Material-UI: The `getOptionLabel` method of Autocomplete returned undefined instead of a string',
@@ -1290,13 +1295,14 @@ describe('<Autocomplete />', () => {
12901295
);
12911296
}).toWarnDev([
12921297
'None of the options match with `"not a good value"`',
1293-
// strict mode renders twice
1294-
React.version.startsWith('16') && 'None of the options match with `"not a good value"`',
1298+
!strictModeDoubleLoggingSupressed && 'None of the options match with `"not a good value"`',
12951299
'None of the options match with `"not a good value"`',
1296-
// strict mode renders twice
1297-
React.version.startsWith('16') && 'None of the options match with `"not a good value"`',
1300+
!strictModeDoubleLoggingSupressed && 'None of the options match with `"not a good value"`',
12981301
// React 18 Strict Effects run mount effects twice which lead to a cascading update
12991302
React.version.startsWith('18') && 'None of the options match with `"not a good value"`',
1303+
React.version.startsWith('18') &&
1304+
!strictModeDoubleLoggingSupressed &&
1305+
'None of the options match with `"not a good value"`',
13001306
]);
13011307
});
13021308

@@ -1322,10 +1328,12 @@ describe('<Autocomplete />', () => {
13221328
);
13231329
}).toWarnDev([
13241330
'returns duplicated headers',
1325-
// strict mode renders twice
1326-
React.version.startsWith('16') && 'returns duplicated headers',
1331+
!strictModeDoubleLoggingSupressed && 'returns duplicated headers',
13271332
// React 18 Strict Effects run mount effects twice which lead to a cascading update
13281333
React.version.startsWith('18') && 'returns duplicated headers',
1334+
React.version.startsWith('18') &&
1335+
!strictModeDoubleLoggingSupressed &&
1336+
'returns duplicated headers',
13291337
]);
13301338
const options = screen.getAllByRole('option').map((el) => el.textContent);
13311339
expect(options).to.have.length(7);

packages/material-ui/src/Breadcrumbs/Breadcrumbs.test.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import * as React from 'react';
22
import { expect } from 'chai';
3-
import { act, describeConformance, createClientRender, screen } from 'test/utils';
3+
import {
4+
act,
5+
describeConformance,
6+
createClientRender,
7+
screen,
8+
strictModeDoubleLoggingSupressed,
9+
} from 'test/utils';
410
import Breadcrumbs, { breadcrumbsClasses as classes } from '@mui/material/Breadcrumbs';
511

612
describe('<Breadcrumbs />', () => {
@@ -86,8 +92,7 @@ describe('<Breadcrumbs />', () => {
8692
);
8793
}).toErrorDev([
8894
'Material-UI: You have provided an invalid combination of props to the Breadcrumbs.\nitemsAfterCollapse={2} + itemsBeforeCollapse={2} >= maxItems={3}',
89-
// strict mode renders twice
90-
React.version.startsWith('16') &&
95+
!strictModeDoubleLoggingSupressed &&
9196
'Material-UI: You have provided an invalid combination of props to the Breadcrumbs.\nitemsAfterCollapse={2} + itemsBeforeCollapse={2} >= maxItems={3}',
9297
]);
9398
expect(screen.getAllByRole('listitem', { hidden: false })).to.have.length(4);

packages/material-ui/src/Hidden/HiddenCss.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { expect } from 'chai';
3-
import { createClientRender } from 'test/utils';
3+
import { createClientRender, strictModeDoubleLoggingSupressed } from 'test/utils';
44
import HiddenCss from './HiddenCss';
55
import { createTheme, ThemeProvider } from '../styles';
66
import classes from './hiddenCssClasses';
@@ -141,8 +141,10 @@ describe('<HiddenCss />', () => {
141141
<div />
142142
</HiddenCss>,
143143
);
144-
}).toErrorDev(
144+
}).toErrorDev([
145145
'Material-UI: Unsupported props received by `<Hidden implementation="css" />`: xxlUp.',
146-
);
146+
!strictModeDoubleLoggingSupressed &&
147+
'Material-UI: Unsupported props received by `<Hidden implementation="css" />`: xxlUp.',
148+
]);
147149
});
148150
});

packages/material-ui/src/InputAdornment/InputAdornment.test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import * as React from 'react';
22
import { expect } from 'chai';
3-
import { createClientRender, describeConformance } from 'test/utils';
3+
import {
4+
createClientRender,
5+
describeConformance,
6+
strictModeDoubleLoggingSupressed,
7+
} from 'test/utils';
48
import { typographyClasses } from '@mui/material/Typography';
59
import InputAdornment, { inputAdornmentClasses as classes } from '@mui/material/InputAdornment';
610
import TextField from '@mui/material/TextField';
@@ -133,10 +137,13 @@ describe('<InputAdornment />', () => {
133137
/>
134138
</FormControl>,
135139
);
136-
}).toErrorDev(
140+
}).toErrorDev([
137141
'Material-UI: The `InputAdornment` variant infers the variant ' +
138142
'prop you do not have to provide one.',
139-
);
143+
!strictModeDoubleLoggingSupressed &&
144+
'Material-UI: The `InputAdornment` variant infers the variant ' +
145+
'prop you do not have to provide one.',
146+
]);
140147
});
141148
});
142149

packages/material-ui/src/LinearProgress/LinearProgress.test.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import * as React from 'react';
22
import { expect } from 'chai';
3-
import { createClientRender, screen, describeConformance } from 'test/utils';
3+
import {
4+
createClientRender,
5+
screen,
6+
describeConformance,
7+
strictModeDoubleLoggingSupressed,
8+
} from 'test/utils';
49
import LinearProgress, { linearProgressClasses as classes } from '@mui/material/LinearProgress';
510

611
describe('<LinearProgress />', () => {
@@ -149,13 +154,18 @@ describe('<LinearProgress />', () => {
149154

150155
expect(() => {
151156
({ rerender } = render(<LinearProgress variant="determinate" value={undefined} />));
152-
}).toErrorDev('Material-UI: You need to provide a value prop');
157+
}).toErrorDev([
158+
'Material-UI: You need to provide a value prop',
159+
!strictModeDoubleLoggingSupressed && 'Material-UI: You need to provide a value prop',
160+
]);
153161

154162
expect(() => {
155163
rerender(<LinearProgress variant="buffer" value={undefined} />);
156164
}).toErrorDev([
157165
'Material-UI: You need to provide a value prop',
158166
'Material-UI: You need to provide a valueBuffer prop',
167+
!strictModeDoubleLoggingSupressed && 'Material-UI: You need to provide a value prop',
168+
!strictModeDoubleLoggingSupressed && 'Material-UI: You need to provide a valueBuffer prop',
159169
]);
160170
});
161171
});

packages/material-ui/src/Menu/Menu.test.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import * as React from 'react';
22
import { spy, useFakeTimers } from 'sinon';
33
import { expect } from 'chai';
4-
import { createClientRender, describeConformance, screen, fireEvent } from 'test/utils';
4+
import {
5+
createClientRender,
6+
describeConformance,
7+
screen,
8+
fireEvent,
9+
strictModeDoubleLoggingSupressed,
10+
} from 'test/utils';
511
import Menu, { menuClasses as classes } from '@mui/material/Menu';
612
import Popover from '@mui/material/Popover';
713

@@ -253,14 +259,14 @@ describe('<Menu />', () => {
253259
it('warns a Fragment is passed as a child', () => {
254260
expect(() => {
255261
render(
256-
<Menu anchorEl={document.createElement('div')} open>
262+
<Menu anchorEl={document.createElement('div')} open={false}>
257263
<React.Fragment />
258264
</Menu>,
259265
);
260266
}).toErrorDev([
261267
"Material-UI: The Menu component doesn't accept a Fragment as a child.",
262-
// twice in StrictMode
263-
"Material-UI: The Menu component doesn't accept a Fragment as a child.",
268+
!strictModeDoubleLoggingSupressed &&
269+
"Material-UI: The Menu component doesn't accept a Fragment as a child.",
264270
]);
265271
});
266272
});

0 commit comments

Comments
 (0)