Skip to content

Commit b1444be

Browse files
committed
Added more tests
1 parent 78e2951 commit b1444be

File tree

1 file changed

+112
-20
lines changed

1 file changed

+112
-20
lines changed

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

Lines changed: 112 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,19 @@ ruleTester.run('no-unused-prop-types', rule, {
12551255
'}'
12561256
].join('\n'),
12571257
parser: 'babel-eslint'
1258+
}, {
1259+
// Destructured function props in componentWillReceiveProps shouldn't throw errors when used createReactClass
1260+
code: [
1261+
'var Hello = createReactClass({',
1262+
' propTypes: {',
1263+
' something: PropTypes.bool,',
1264+
' },',
1265+
' componentWillReceiveProps ({something}) {',
1266+
' doSomething(something);',
1267+
' }',
1268+
'})'
1269+
].join('\n'),
1270+
parser: 'babel-eslint'
12581271
}, {
12591272
// Destructured props in the constructor shouldn't throw errors
12601273
code: [
@@ -1285,57 +1298,57 @@ ruleTester.run('no-unused-prop-types', rule, {
12851298
].join('\n'),
12861299
parser: 'babel-eslint'
12871300
}, {
1288-
// Destructured props in the `componentWillReceiveProps` method shouldn't throw errors
1301+
// Destructured props in the `shouldComponentUpdate` method shouldn't throw errors
12891302
code: [
12901303
'class Hello extends Component {',
12911304
' static propTypes = {',
12921305
' something: PropTypes.bool',
12931306
' }',
1294-
' componentWillReceiveProps (nextProps, nextState) {',
1307+
' shouldComponentUpdate (nextProps, nextState) {',
12951308
' const {something} = nextProps;',
12961309
' return something;',
12971310
' }',
12981311
'}'
12991312
].join('\n'),
13001313
parser: 'babel-eslint'
13011314
}, {
1302-
// Destructured function props in the `componentWillReceiveProps` method shouldn't throw errors
1315+
// Destructured props in `shouldComponentUpdate` shouldn't throw errors when used createReactClass
13031316
code: [
1304-
'class Hello extends Component {',
1305-
' static propTypes = {',
1306-
' something: PropTypes.bool',
1307-
' }',
1308-
' componentWillReceiveProps ({something}, nextState) {',
1317+
'var Hello = createReactClass({',
1318+
' propTypes: {',
1319+
' something: PropTypes.bool,',
1320+
' },',
1321+
' shouldComponentUpdate (nextProps, nextState) {',
1322+
' const {something} = nextProps;',
13091323
' return something;',
13101324
' }',
1311-
'}'
1325+
'})'
13121326
].join('\n'),
13131327
parser: 'babel-eslint'
13141328
}, {
1315-
// Destructured props in the `shouldComponentUpdate` method shouldn't throw errors
1329+
// Destructured function props in the `shouldComponentUpdate` method shouldn't throw errors
13161330
code: [
13171331
'class Hello extends Component {',
13181332
' static propTypes = {',
13191333
' something: PropTypes.bool',
13201334
' }',
1321-
' shouldComponentUpdate (nextProps, nextState) {',
1322-
' const {something} = nextProps;',
1335+
' shouldComponentUpdate ({something}, nextState) {',
13231336
' return something;',
13241337
' }',
13251338
'}'
13261339
].join('\n'),
13271340
parser: 'babel-eslint'
13281341
}, {
1329-
// Destructured function props in the `shouldComponentUpdate` method shouldn't throw errors
1342+
// Destructured function props in `shouldComponentUpdate` shouldn't throw errors when used createReactClass
13301343
code: [
1331-
'class Hello extends Component {',
1332-
' static propTypes = {',
1333-
' something: PropTypes.bool',
1334-
' }',
1344+
'var Hello = createReactClass({',
1345+
' propTypes: {',
1346+
' something: PropTypes.bool,',
1347+
' },',
13351348
' shouldComponentUpdate ({something}, nextState) {',
13361349
' return something;',
13371350
' }',
1338-
'}'
1351+
'})'
13391352
].join('\n'),
13401353
parser: 'babel-eslint'
13411354
}, {
@@ -1352,6 +1365,20 @@ ruleTester.run('no-unused-prop-types', rule, {
13521365
'}'
13531366
].join('\n'),
13541367
parser: 'babel-eslint'
1368+
}, {
1369+
// Destructured props in `componentWillUpdate` shouldn't throw errors when used createReactClass
1370+
code: [
1371+
'var Hello = createReactClass({',
1372+
' propTypes: {',
1373+
' something: PropTypes.bool,',
1374+
' },',
1375+
' componentWillUpdate (nextProps, nextState) {',
1376+
' const {something} = nextProps;',
1377+
' return something;',
1378+
' }',
1379+
'})'
1380+
].join('\n'),
1381+
parser: 'babel-eslint'
13551382
}, {
13561383
// Destructured function props in the `componentWillUpdate` method shouldn't throw errors
13571384
code: [
@@ -1365,33 +1392,73 @@ ruleTester.run('no-unused-prop-types', rule, {
13651392
'}'
13661393
].join('\n'),
13671394
parser: 'babel-eslint'
1395+
}, {
1396+
// Destructured function props in the `componentWillUpdate` method shouldn't throw errors when used createReactClass
1397+
code: [
1398+
'var Hello = createReactClass({',
1399+
' propTypes: {',
1400+
' something: PropTypes.bool,',
1401+
' },',
1402+
' componentWillUpdate ({something}, nextState) {',
1403+
' return something;',
1404+
' }',
1405+
'})'
1406+
].join('\n'),
1407+
parser: 'babel-eslint'
13681408
}, {
13691409
// Destructured props in the `componentDidUpdate` method shouldn't throw errors
13701410
code: [
13711411
'class Hello extends Component {',
13721412
' static propTypes = {',
13731413
' something: PropTypes.bool',
13741414
' }',
1375-
' componentDidUpdate (prevProps, nextState) {',
1415+
' componentDidUpdate (prevProps, prevState) {',
13761416
' const {something} = prevProps;',
13771417
' return something;',
13781418
' }',
13791419
'}'
13801420
].join('\n'),
13811421
parser: 'babel-eslint'
1422+
}, {
1423+
// Destructured props in `componentDidUpdate` shouldn't throw errors when used createReactClass
1424+
code: [
1425+
'var Hello = createReactClass({',
1426+
' propTypes: {',
1427+
' something: PropTypes.bool,',
1428+
' },',
1429+
' componentDidUpdate (prevProps, prevState) {',
1430+
' const {something} = prevProps;',
1431+
' return something;',
1432+
' }',
1433+
'})'
1434+
].join('\n'),
1435+
parser: 'babel-eslint'
13821436
}, {
13831437
// Destructured function props in the `componentDidUpdate` method shouldn't throw errors
13841438
code: [
13851439
'class Hello extends Component {',
13861440
' static propTypes = {',
13871441
' something: PropTypes.bool',
13881442
' }',
1389-
' componentDidUpdate ({something}, nextState) {',
1443+
' componentDidUpdate ({something}, prevState) {',
13901444
' return something;',
13911445
' }',
13921446
'}'
13931447
].join('\n'),
13941448
parser: 'babel-eslint'
1449+
}, {
1450+
// Destructured function props in the `componentDidUpdate` method shouldn't throw errors when used createReactClass
1451+
code: [
1452+
'var Hello = createReactClass({',
1453+
' propTypes: {',
1454+
' something: PropTypes.bool,',
1455+
' },',
1456+
' componentDidUpdate ({something}, prevState) {',
1457+
' return something;',
1458+
' }',
1459+
'})'
1460+
].join('\n'),
1461+
parser: 'babel-eslint'
13951462
}, {
13961463
// Destructured state props in `componentDidUpdate` [Issue #825]
13971464
code: [
@@ -1405,6 +1472,19 @@ ruleTester.run('no-unused-prop-types', rule, {
14051472
'}'
14061473
].join('\n'),
14071474
parser: 'babel-eslint'
1475+
}, {
1476+
// Destructured state props in `componentDidUpdate` [Issue #825] when used createReactClass
1477+
code: [
1478+
'var Hello = createReactClass({',
1479+
' propTypes: {',
1480+
' something: PropTypes.bool,',
1481+
' },',
1482+
' componentDidUpdate ({something}, {state1, state2}) {',
1483+
' return something;',
1484+
' }',
1485+
'})'
1486+
].join('\n'),
1487+
parser: 'babel-eslint'
14081488
}, {
14091489
// Destructured state props in `componentDidUpdate` without custom parser [Issue #825]
14101490
code: [
@@ -1417,6 +1497,18 @@ ruleTester.run('no-unused-prop-types', rule, {
14171497
' }',
14181498
'});'
14191499
].join('\n')
1500+
}, {
1501+
// Destructured state props in `componentDidUpdate` without custom parser [Issue #825] when used createReactClass
1502+
code: [
1503+
'var Hello = createReactClass({',
1504+
' propTypes: {',
1505+
' something: PropTypes.bool,',
1506+
' },',
1507+
' componentDidUpdate: function ({something}, {state1, state2}) {',
1508+
' return something;',
1509+
' }',
1510+
'})'
1511+
].join('\n')
14201512
}, {
14211513
// Destructured props in a stateless function
14221514
code: [

0 commit comments

Comments
 (0)