Skip to content

Commit

Permalink
Added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri-sakharov committed Feb 5, 2018
1 parent 24658b5 commit 3d83d13
Showing 1 changed file with 139 additions and 0 deletions.
139 changes: 139 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Expand Up @@ -1228,6 +1228,19 @@ ruleTester.run('no-unused-prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
// Destructured props in componentWillReceiveProps shouldn't throw errors
code: [
'class Hello extends Component {',
' componentWillReceiveProps (nextProps) {',
' const {something} = nextProps;',
' doSomething(something);',
' }',
'}',
'Hello.propTypes = {',
' something: PropTypes.bool,',
'};'
].join('\n')
}, {
// Destructured props in componentWillReceiveProps shouldn't throw errors when used createReactClass
code: [
Expand Down Expand Up @@ -1268,6 +1281,18 @@ ruleTester.run('no-unused-prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
// Destructured function props in componentWillReceiveProps shouldn't throw errors
code: [
'class Hello extends Component {',
' componentWillReceiveProps ({something}) {',
' doSomething(something);',
' }',
'}',
'Hello.propTypes = {',
' something: PropTypes.bool,',
'};'
].join('\n')
}, {
// Destructured function props in componentWillReceiveProps shouldn't throw errors when used createReactClass
code: [
Expand Down Expand Up @@ -1308,6 +1333,20 @@ ruleTester.run('no-unused-prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
// Destructured props in the constructor shouldn't throw errors
code: [
'class Hello extends Component {',
' constructor (props) {',
' super(props);',
' const {something} = props;',
' doSomething(something);',
' }',
'}',
'Hello.propTypes = {',
' something: PropTypes.bool,',
'};'
].join('\n')
}, {
// Destructured function props in the constructor shouldn't throw errors
code: [
Expand All @@ -1322,6 +1361,19 @@ ruleTester.run('no-unused-prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
// Destructured function props in the constructor shouldn't throw errors
code: [
'class Hello extends Component {',
' constructor ({something}) {',
' super({something});',
' doSomething(something);',
' }',
'}',
'Hello.propTypes = {',
' something: PropTypes.bool,',
'};'
].join('\n')
}, {
// Destructured props in the `shouldComponentUpdate` method shouldn't throw errors
code: [
Expand All @@ -1336,6 +1388,19 @@ ruleTester.run('no-unused-prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
// Destructured props in the `shouldComponentUpdate` method shouldn't throw errors
code: [
'class Hello extends Component {',
' shouldComponentUpdate (nextProps, nextState) {',
' const {something} = nextProps;',
' return something;',
' }',
'}',
'Hello.propTypes = {',
' something: PropTypes.bool,',
'};'
].join('\n')
}, {
// Destructured props in `shouldComponentUpdate` shouldn't throw errors when used createReactClass
code: [
Expand Down Expand Up @@ -1376,6 +1441,18 @@ ruleTester.run('no-unused-prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
// Destructured function props in the `shouldComponentUpdate` method shouldn't throw errors
code: [
'class Hello extends Component {',
' shouldComponentUpdate ({something}, nextState) {',
' return something;',
' }',
'}',
'Hello.propTypes = {',
' something: PropTypes.bool,',
'};'
].join('\n')
}, {
// Destructured function props in `shouldComponentUpdate` shouldn't throw errors when used createReactClass
code: [
Expand Down Expand Up @@ -1415,6 +1492,19 @@ ruleTester.run('no-unused-prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
// Destructured props in the `componentWillUpdate` method shouldn't throw errors
code: [
'class Hello extends Component {',
' componentWillUpdate (nextProps, nextState) {',
' const {something} = nextProps;',
' return something;',
' }',
'}',
'Hello.propTypes = {',
' something: PropTypes.bool,',
'};'
].join('\n')
}, {
// Destructured props in `componentWillUpdate` shouldn't throw errors when used createReactClass
code: [
Expand Down Expand Up @@ -1455,6 +1545,18 @@ ruleTester.run('no-unused-prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
// Destructured function props in the `componentWillUpdate` method shouldn't throw errors
code: [
'class Hello extends Component {',
' componentWillUpdate ({something}, nextState) {',
' return something;',
' }',
'}',
'Hello.propTypes = {',
' something: PropTypes.bool,',
'};'
].join('\n')
}, {
// Destructured function props in the `componentWillUpdate` method shouldn't throw errors when used createReactClass
code: [
Expand Down Expand Up @@ -1494,6 +1596,19 @@ ruleTester.run('no-unused-prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
// Destructured props in the `componentDidUpdate` method shouldn't throw errors
code: [
'class Hello extends Component {',
' componentDidUpdate (prevProps, prevState) {',
' const {something} = prevProps;',
' return something;',
' }',
'}',
'Hello.propTypes = {',
' something: PropTypes.bool,',
'};'
].join('\n')
}, {
// Destructured props in `componentDidUpdate` shouldn't throw errors when used createReactClass
code: [
Expand Down Expand Up @@ -1534,6 +1649,18 @@ ruleTester.run('no-unused-prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
// Destructured function props in the `componentDidUpdate` method shouldn't throw errors
code: [
'class Hello extends Component {',
' componentDidUpdate ({something}, prevState) {',
' return something;',
' }',
'}',
'Hello.propTypes = {',
' something: PropTypes.bool,',
'};'
].join('\n')
}, {
// Destructured function props in the `componentDidUpdate` method shouldn't throw errors when used createReactClass
code: [
Expand Down Expand Up @@ -1572,6 +1699,18 @@ ruleTester.run('no-unused-prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
// Destructured state props in `componentDidUpdate` [Issue #825]
code: [
'class Hello extends Component {',
' componentDidUpdate ({something}, {state1, state2}) {',
' return something;',
' }',
'}',
'Hello.propTypes = {',
' something: PropTypes.bool,',
'};'
].join('\n')
}, {
// Destructured state props in `componentDidUpdate` [Issue #825] when used createReactClass
code: [
Expand Down

0 comments on commit 3d83d13

Please sign in to comment.