From 9265f8c78eb7e9e0bc799c63589dfcdfe5fb8272 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Tue, 7 Apr 2020 09:57:29 +0200 Subject: [PATCH] chore: Use .checkPropTypes instead of render + propTypes --- .eslintrc.js | 5 ++- .../src/styled/styled.test.js | 10 +++-- .../src/withTheme/withTheme.test.js | 8 +++- .../src/chainPropTypes.test.js | 1 + .../src/ButtonBase/ButtonBase.test.js | 11 +++-- .../src/CardMedia/CardMedia.test.js | 2 +- .../src/ExpansionPanel/ExpansionPanel.test.js | 26 ++++++------ .../src/IconButton/IconButton.test.js | 10 +++-- .../material-ui/src/ListItem/ListItem.test.js | 16 +++++--- .../material-ui/src/Popper/Popper.test.js | 18 +++++---- .../material-ui/src/Slider/Slider.test.js | 18 ++++++++- .../SwipeableDrawer/SwipeableDrawer.test.js | 40 +++++++++++-------- .../TablePagination/TablePagination.test.js | 26 ++++++------ .../src/utils/deprecatedPropType.test.js | 3 +- 14 files changed, 121 insertions(+), 73 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index c8d140df0e113f..dcc9bc7410611c 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -129,7 +129,10 @@ module.exports = { // test to `beforeEach`. // `beforeEach`+`afterEach` also means that the `beforeEach` // is cleaned up in `afterEach` if the test causes a crash - 'mocha/no-hooks-for-single-case': 'off' + 'mocha/no-hooks-for-single-case': 'off', + + // They are accessed to test custom validator implementation with PropTypes.checkPropTypes + 'react/forbid-foreign-prop-types': 'off', }, }, { diff --git a/packages/material-ui-styles/src/styled/styled.test.js b/packages/material-ui-styles/src/styled/styled.test.js index 8bb780ca86143f..e1203ea88bfe82 100644 --- a/packages/material-ui-styles/src/styled/styled.test.js +++ b/packages/material-ui-styles/src/styled/styled.test.js @@ -101,11 +101,13 @@ describe('styled', () => { }); it('warns if it cant detect the secondary action properly', () => { - mount( - -
Styled Components
-
, + PropTypes.checkPropTypes( + StyledButton.propTypes, + { clone: true, component: 'div' }, + 'prop', + 'StyledButton', ); + assert.strictEqual(consoleErrorMock.callCount(), 1); assert.include( consoleErrorMock.messages()[0], diff --git a/packages/material-ui-styles/src/withTheme/withTheme.test.js b/packages/material-ui-styles/src/withTheme/withTheme.test.js index 3db049a30ebd79..511a55a9e0dc70 100644 --- a/packages/material-ui-styles/src/withTheme/withTheme.test.js +++ b/packages/material-ui-styles/src/withTheme/withTheme.test.js @@ -94,8 +94,12 @@ describe('withTheme', () => { it('is deprecated', () => { const ThemedDiv = withTheme('div'); - - mount(); + PropTypes.checkPropTypes( + ThemedDiv.propTypes, + { innerRef: React.createRef() }, + 'prop', + 'ThemedDiv', + ); assert.strictEqual(consoleErrorMock.callCount(), 1); assert.include( diff --git a/packages/material-ui-utils/src/chainPropTypes.test.js b/packages/material-ui-utils/src/chainPropTypes.test.js index 2820394e2e6ca1..aa95bf371b3550 100644 --- a/packages/material-ui-utils/src/chainPropTypes.test.js +++ b/packages/material-ui-utils/src/chainPropTypes.test.js @@ -11,6 +11,7 @@ describe('chainPropTypes', () => { beforeEach(() => { consoleErrorMock.spy(); + PropTypes.resetWarningCache(); }); afterEach(() => { diff --git a/packages/material-ui/src/ButtonBase/ButtonBase.test.js b/packages/material-ui/src/ButtonBase/ButtonBase.test.js index 268a5ebbf45cc1..08d6f2bd7c4a80 100644 --- a/packages/material-ui/src/ButtonBase/ButtonBase.test.js +++ b/packages/material-ui/src/ButtonBase/ButtonBase.test.js @@ -929,11 +929,16 @@ describe('', () => { return