Skip to content

Commit 026fea2

Browse files
authored
[test] Match against messages not args on console methods (#20046)
1 parent d47c518 commit 026fea2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+148
-95
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"eslint-plugin-react": "^7.14.3",
102102
"eslint-plugin-react-hooks": "^2.1.1",
103103
"expect-puppeteer": "^4.3.0",
104+
"format-util": "^1.0.5",
104105
"fs-extra": "^8.1.0",
105106
"glob": "^7.1.2",
106107
"glob-gitignore": "^1.0.11",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ describe('<Autocomplete />', () => {
777777
expect(handleChange.callCount).to.equal(1);
778778
expect(handleChange.args[0][1]).to.equal('a');
779779
expect(consoleErrorMock.callCount()).to.equal(2); // strict mode renders twice
780-
expect(consoleErrorMock.args()[0][0]).to.include(
780+
expect(consoleErrorMock.messages()[0]).to.include(
781781
'For the input option: "a", `getOptionLabel` returns: undefined',
782782
);
783783
});
@@ -806,7 +806,7 @@ describe('<Autocomplete />', () => {
806806
fireEvent.keyDown(document.activeElement, { key: 'Enter' });
807807

808808
expect(consoleErrorMock.callCount()).to.equal(1); // strict mode renders twice
809-
expect(consoleErrorMock.args()[0][0]).to.include(
809+
expect(consoleErrorMock.messages()[0]).to.include(
810810
'The component expects a single value to match a given option but found 2 matches.',
811811
);
812812
});

packages/material-ui-lab/src/TreeView/TreeView.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('<TreeView />', () => {
4545
);
4646

4747
setProps({ expanded: undefined });
48-
expect(consoleErrorMock.args()[0][0]).to.include(
48+
expect(consoleErrorMock.messages()[0]).to.include(
4949
'A component is changing a controlled TreeView to be uncontrolled',
5050
);
5151
});
@@ -58,7 +58,7 @@ describe('<TreeView />', () => {
5858
);
5959

6060
setProps({ selected: undefined });
61-
expect(consoleErrorMock.args()[0][0]).to.include(
61+
expect(consoleErrorMock.messages()[0]).to.include(
6262
'A component is changing a controlled TreeView to be uncontrolled',
6363
);
6464
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ describe('StylesProvider', () => {
161161
);
162162
assert.strictEqual(consoleErrorMock.callCount(), 1);
163163
assert.include(
164-
consoleErrorMock.args()[0][0],
164+
consoleErrorMock.messages()[0],
165165
'you cannot use the jss and injectFirst props at the same time',
166166
);
167167
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe('ThemeProvider', () => {
144144
</ThemeProvider>,
145145
);
146146
assert.strictEqual(consoleErrorMock.callCount(), 2); // twice in strict mode
147-
assert.include(consoleErrorMock.args()[0][0], 'However, no outer theme is present.');
147+
assert.include(consoleErrorMock.messages()[0], 'However, no outer theme is present.');
148148
});
149149

150150
it('should warn about wrong theme function', () => {
@@ -158,7 +158,7 @@ describe('ThemeProvider', () => {
158158
);
159159
assert.strictEqual(consoleErrorMock.callCount(), 2);
160160
assert.include(
161-
consoleErrorMock.args()[0][0],
161+
consoleErrorMock.messages()[0],
162162
'you should return an object from your theme function',
163163
);
164164
});

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('makeStyles', () => {
9393
assert.deepEqual(extendedClasses, { root: baseClasses.root, bar: 'undefined foo' });
9494
assert.strictEqual(consoleErrorMock.callCount(), 1);
9595
assert.include(
96-
consoleErrorMock.args()[0][0],
96+
consoleErrorMock.messages()[0],
9797
'Material-UI: the key `bar` provided to the classes prop is not implemented',
9898
);
9999
});
@@ -102,9 +102,9 @@ describe('makeStyles', () => {
102102
const output = mountWithProps();
103103
output.wrapper.setProps({ classes: 'foo' });
104104
assert.strictEqual(consoleErrorMock.callCount() >= 1, true);
105-
const args = consoleErrorMock.args();
105+
const messages = consoleErrorMock.messages();
106106
assert.include(
107-
consoleErrorMock.args()[args.length - 1][0],
107+
messages[messages.length - 1],
108108
'You might want to use the className prop instead',
109109
);
110110
});
@@ -117,7 +117,7 @@ describe('makeStyles', () => {
117117
assert.deepEqual(extendedClasses, { root: `${baseClasses.root} [object Object]` });
118118
assert.strictEqual(consoleErrorMock.callCount(), 1);
119119
assert.include(
120-
consoleErrorMock.args()[0][0],
120+
consoleErrorMock.messages()[0],
121121
'Material-UI: the key `root` provided to the classes prop is not valid',
122122
);
123123
});
@@ -129,7 +129,7 @@ describe('makeStyles', () => {
129129
mountWithProps2({});
130130
});
131131
assert.strictEqual(consoleErrorMock.callCount(), 4);
132-
assert.include(consoleErrorMock.args()[1][0], 'the `styles` argument provided is invalid');
132+
assert.include(consoleErrorMock.messages()[1], 'the `styles` argument provided is invalid');
133133
});
134134
});
135135

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('styled', () => {
108108
);
109109
assert.strictEqual(consoleErrorMock.callCount(), 1);
110110
assert.include(
111-
consoleErrorMock.args()[0][0],
111+
consoleErrorMock.messages()[0],
112112
'You can not use the clone and component prop at the same time',
113113
);
114114
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('withStyles', () => {
9191

9292
// assert.strictEqual(consoleErrorMock.callCount(), 1);
9393
// assert.include(
94-
// consoleErrorMock.args()[0][0],
94+
// consoleErrorMock.messages()[0],
9595
// 'Warning: Failed prop type: Material-UI: the `innerRef` prop is deprecated',
9696
// );
9797
// });

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('withTheme', () => {
9999

100100
assert.strictEqual(consoleErrorMock.callCount(), 1);
101101
assert.include(
102-
consoleErrorMock.args()[0][0],
102+
consoleErrorMock.messages()[0],
103103
'Warning: Failed prop type: Material-UI: the `innerRef` prop is deprecated',
104104
);
105105
});

packages/material-ui-system/src/spacing.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ describe('spacing', () => {
5757
});
5858
assert.deepEqual(output, { padding: undefined });
5959
assert.strictEqual(consoleErrorMock.callCount(), 1);
60-
assert.match(consoleErrorMock.args()[0][0], /the value provided \(3\) overflows\./);
61-
assert.match(consoleErrorMock.args()[0][0], /The supported values are: \[0,3,5\]\./);
62-
assert.match(consoleErrorMock.args()[0][0], /3 > 2, you need to add the missing values\./);
60+
assert.match(consoleErrorMock.messages()[0], /the value provided \(3\) overflows\./);
61+
assert.match(consoleErrorMock.messages()[0], /The supported values are: \[0,3,5\]\./);
62+
assert.match(consoleErrorMock.messages()[0], /3 > 2, you need to add the missing values\./);
6363
});
6464

6565
it('should warn if the theme transformer is invalid', () => {
@@ -72,11 +72,11 @@ describe('spacing', () => {
7272
assert.deepEqual(output, { padding: undefined });
7373
assert.strictEqual(consoleErrorMock.callCount(), 1);
7474
assert.match(
75-
consoleErrorMock.args()[0][0],
75+
consoleErrorMock.messages()[0],
7676
/the `theme.spacing` value \(\[object Object\]\) is invalid\./,
7777
);
7878
assert.match(
79-
consoleErrorMock.args()[0][0],
79+
consoleErrorMock.messages()[0],
8080
/It should be a number, an array or a function\./,
8181
);
8282
});

0 commit comments

Comments
 (0)