From 5488fffc0e6dd28065e6f430d97f2365b06b4a50 Mon Sep 17 00:00:00 2001 From: Diana Suvorova Date: Fri, 21 Jul 2017 15:10:55 -0700 Subject: [PATCH] test cases from #816 --- tests/lib/rules/no-unused-prop-types.js | 54 +++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/lib/rules/no-unused-prop-types.js b/tests/lib/rules/no-unused-prop-types.js index 93960233e7..266f59f123 100644 --- a/tests/lib/rules/no-unused-prop-types.js +++ b/tests/lib/rules/no-unused-prop-types.js @@ -1858,6 +1858,39 @@ ruleTester.run('no-unused-prop-types', rule, { '}' ].join('\n'), parserOptions: Object.assign({}, parserOptions, {ecmaVersion: 2017}) + }, + { + // Destructured assignment with Shape propTypes issue #816 + code: [ + 'export default class NavigationButton extends React.Component {', + ' static propTypes = {', + ' route: PropTypes.shape({', + ' getBarTintColor: PropTypes.func.isRequired,', + ' }).isRequired,', + ' };', + + ' renderTitle() {', + ' const { route } = this.props;', + ' return TITLE;', + ' }', + '}' + ].join('\n'), + parser: 'babel-eslint' + }, { + // Destructured assignment without Shape propTypes issue #816 + code: [ + 'const Component = ({ children: aNode }) => (', + '
{aNode}
', + ');', + + 'Component.defaultProps = {', + ' children: null,', + '};', + + 'Component.propTypes = {', + ' children: React.PropTypes.node,', + '};' + ].join('\n') } ], @@ -3189,8 +3222,29 @@ ruleTester.run('no-unused-prop-types', rule, { }, { message: '\'prop2.*\' PropType is defined but prop is never used' }] + }, { + // Destructured assignment with Shape propTypes with skipShapeProps off issue #816 + code: [ + 'export default class NavigationButton extends React.Component {', + ' static propTypes = {', + ' route: PropTypes.shape({', + ' getBarTintColor: PropTypes.func.isRequired,', + ' }).isRequired,', + ' };', + ' renderTitle() {', + ' const { route } = this.props;', + ' return TITLE;', + ' }', + '}' + ].join('\n'), + parser: 'babel-eslint', + options: [{skipShapeProps: false}], + errors: [{ + message: '\'route.getBarTintColor\' PropType is defined but prop is never used' + }] } + /* , { // Enable this when the following issue is fixed // https://github.com/yannickcr/eslint-plugin-react/issues/296