Skip to content

Commit 3d83d13

Browse files
committed
Added more tests
1 parent 24658b5 commit 3d83d13

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed

tests/lib/rules/no-unused-prop-types.js

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,19 @@ ruleTester.run('no-unused-prop-types', rule, {
12281228
'}'
12291229
].join('\n'),
12301230
parser: 'babel-eslint'
1231+
}, {
1232+
// Destructured props in componentWillReceiveProps shouldn't throw errors
1233+
code: [
1234+
'class Hello extends Component {',
1235+
' componentWillReceiveProps (nextProps) {',
1236+
' const {something} = nextProps;',
1237+
' doSomething(something);',
1238+
' }',
1239+
'}',
1240+
'Hello.propTypes = {',
1241+
' something: PropTypes.bool,',
1242+
'};'
1243+
].join('\n')
12311244
}, {
12321245
// Destructured props in componentWillReceiveProps shouldn't throw errors when used createReactClass
12331246
code: [
@@ -1268,6 +1281,18 @@ ruleTester.run('no-unused-prop-types', rule, {
12681281
'}'
12691282
].join('\n'),
12701283
parser: 'babel-eslint'
1284+
}, {
1285+
// Destructured function props in componentWillReceiveProps shouldn't throw errors
1286+
code: [
1287+
'class Hello extends Component {',
1288+
' componentWillReceiveProps ({something}) {',
1289+
' doSomething(something);',
1290+
' }',
1291+
'}',
1292+
'Hello.propTypes = {',
1293+
' something: PropTypes.bool,',
1294+
'};'
1295+
].join('\n')
12711296
}, {
12721297
// Destructured function props in componentWillReceiveProps shouldn't throw errors when used createReactClass
12731298
code: [
@@ -1308,6 +1333,20 @@ ruleTester.run('no-unused-prop-types', rule, {
13081333
'}'
13091334
].join('\n'),
13101335
parser: 'babel-eslint'
1336+
}, {
1337+
// Destructured props in the constructor shouldn't throw errors
1338+
code: [
1339+
'class Hello extends Component {',
1340+
' constructor (props) {',
1341+
' super(props);',
1342+
' const {something} = props;',
1343+
' doSomething(something);',
1344+
' }',
1345+
'}',
1346+
'Hello.propTypes = {',
1347+
' something: PropTypes.bool,',
1348+
'};'
1349+
].join('\n')
13111350
}, {
13121351
// Destructured function props in the constructor shouldn't throw errors
13131352
code: [
@@ -1322,6 +1361,19 @@ ruleTester.run('no-unused-prop-types', rule, {
13221361
'}'
13231362
].join('\n'),
13241363
parser: 'babel-eslint'
1364+
}, {
1365+
// Destructured function props in the constructor shouldn't throw errors
1366+
code: [
1367+
'class Hello extends Component {',
1368+
' constructor ({something}) {',
1369+
' super({something});',
1370+
' doSomething(something);',
1371+
' }',
1372+
'}',
1373+
'Hello.propTypes = {',
1374+
' something: PropTypes.bool,',
1375+
'};'
1376+
].join('\n')
13251377
}, {
13261378
// Destructured props in the `shouldComponentUpdate` method shouldn't throw errors
13271379
code: [
@@ -1336,6 +1388,19 @@ ruleTester.run('no-unused-prop-types', rule, {
13361388
'}'
13371389
].join('\n'),
13381390
parser: 'babel-eslint'
1391+
}, {
1392+
// Destructured props in the `shouldComponentUpdate` method shouldn't throw errors
1393+
code: [
1394+
'class Hello extends Component {',
1395+
' shouldComponentUpdate (nextProps, nextState) {',
1396+
' const {something} = nextProps;',
1397+
' return something;',
1398+
' }',
1399+
'}',
1400+
'Hello.propTypes = {',
1401+
' something: PropTypes.bool,',
1402+
'};'
1403+
].join('\n')
13391404
}, {
13401405
// Destructured props in `shouldComponentUpdate` shouldn't throw errors when used createReactClass
13411406
code: [
@@ -1376,6 +1441,18 @@ ruleTester.run('no-unused-prop-types', rule, {
13761441
'}'
13771442
].join('\n'),
13781443
parser: 'babel-eslint'
1444+
}, {
1445+
// Destructured function props in the `shouldComponentUpdate` method shouldn't throw errors
1446+
code: [
1447+
'class Hello extends Component {',
1448+
' shouldComponentUpdate ({something}, nextState) {',
1449+
' return something;',
1450+
' }',
1451+
'}',
1452+
'Hello.propTypes = {',
1453+
' something: PropTypes.bool,',
1454+
'};'
1455+
].join('\n')
13791456
}, {
13801457
// Destructured function props in `shouldComponentUpdate` shouldn't throw errors when used createReactClass
13811458
code: [
@@ -1415,6 +1492,19 @@ ruleTester.run('no-unused-prop-types', rule, {
14151492
'}'
14161493
].join('\n'),
14171494
parser: 'babel-eslint'
1495+
}, {
1496+
// Destructured props in the `componentWillUpdate` method shouldn't throw errors
1497+
code: [
1498+
'class Hello extends Component {',
1499+
' componentWillUpdate (nextProps, nextState) {',
1500+
' const {something} = nextProps;',
1501+
' return something;',
1502+
' }',
1503+
'}',
1504+
'Hello.propTypes = {',
1505+
' something: PropTypes.bool,',
1506+
'};'
1507+
].join('\n')
14181508
}, {
14191509
// Destructured props in `componentWillUpdate` shouldn't throw errors when used createReactClass
14201510
code: [
@@ -1455,6 +1545,18 @@ ruleTester.run('no-unused-prop-types', rule, {
14551545
'}'
14561546
].join('\n'),
14571547
parser: 'babel-eslint'
1548+
}, {
1549+
// Destructured function props in the `componentWillUpdate` method shouldn't throw errors
1550+
code: [
1551+
'class Hello extends Component {',
1552+
' componentWillUpdate ({something}, nextState) {',
1553+
' return something;',
1554+
' }',
1555+
'}',
1556+
'Hello.propTypes = {',
1557+
' something: PropTypes.bool,',
1558+
'};'
1559+
].join('\n')
14581560
}, {
14591561
// Destructured function props in the `componentWillUpdate` method shouldn't throw errors when used createReactClass
14601562
code: [
@@ -1494,6 +1596,19 @@ ruleTester.run('no-unused-prop-types', rule, {
14941596
'}'
14951597
].join('\n'),
14961598
parser: 'babel-eslint'
1599+
}, {
1600+
// Destructured props in the `componentDidUpdate` method shouldn't throw errors
1601+
code: [
1602+
'class Hello extends Component {',
1603+
' componentDidUpdate (prevProps, prevState) {',
1604+
' const {something} = prevProps;',
1605+
' return something;',
1606+
' }',
1607+
'}',
1608+
'Hello.propTypes = {',
1609+
' something: PropTypes.bool,',
1610+
'};'
1611+
].join('\n')
14971612
}, {
14981613
// Destructured props in `componentDidUpdate` shouldn't throw errors when used createReactClass
14991614
code: [
@@ -1534,6 +1649,18 @@ ruleTester.run('no-unused-prop-types', rule, {
15341649
'}'
15351650
].join('\n'),
15361651
parser: 'babel-eslint'
1652+
}, {
1653+
// Destructured function props in the `componentDidUpdate` method shouldn't throw errors
1654+
code: [
1655+
'class Hello extends Component {',
1656+
' componentDidUpdate ({something}, prevState) {',
1657+
' return something;',
1658+
' }',
1659+
'}',
1660+
'Hello.propTypes = {',
1661+
' something: PropTypes.bool,',
1662+
'};'
1663+
].join('\n')
15371664
}, {
15381665
// Destructured function props in the `componentDidUpdate` method shouldn't throw errors when used createReactClass
15391666
code: [
@@ -1572,6 +1699,18 @@ ruleTester.run('no-unused-prop-types', rule, {
15721699
'}'
15731700
].join('\n'),
15741701
parser: 'babel-eslint'
1702+
}, {
1703+
// Destructured state props in `componentDidUpdate` [Issue #825]
1704+
code: [
1705+
'class Hello extends Component {',
1706+
' componentDidUpdate ({something}, {state1, state2}) {',
1707+
' return something;',
1708+
' }',
1709+
'}',
1710+
'Hello.propTypes = {',
1711+
' something: PropTypes.bool,',
1712+
'};'
1713+
].join('\n')
15751714
}, {
15761715
// Destructured state props in `componentDidUpdate` [Issue #825] when used createReactClass
15771716
code: [

0 commit comments

Comments
 (0)