Skip to content

Commit 553bf95

Browse files
sstern6ljharb
authored andcommitted
Chore: Add tests for prop-types destructuring
1 parent 7d07c37 commit 553bf95

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/lib/rules/prop-types.js

+52
Original file line numberDiff line numberDiff line change
@@ -2235,6 +2235,58 @@ ruleTester.run('prop-types', rule, {
22352235
column: 35,
22362236
type: 'Identifier'
22372237
}]
2238+
}, {
2239+
code: [
2240+
'class Hello extends React.Component {',
2241+
' render() {',
2242+
' const { name, ...rest } = this.props',
2243+
' return <div>Hello</div>;',
2244+
' }',
2245+
'}'
2246+
].join('\n'),
2247+
errors: [{
2248+
message: '\'name\' is missing in props validation',
2249+
line: 3,
2250+
column: 13,
2251+
type: 'Property'
2252+
}]
2253+
}, {
2254+
code: [
2255+
'class Hello extends React.Component {',
2256+
' render() {',
2257+
' const { name, title, ...rest } = this.props',
2258+
' return <div>Hello</div>;',
2259+
' }',
2260+
'}',
2261+
'Hello.propTypes = {',
2262+
' name: PropTypes.string',
2263+
'}'
2264+
].join('\n'),
2265+
errors: [{
2266+
message: '\'title\' is missing in props validation',
2267+
line: 3,
2268+
column: 19,
2269+
type: 'Property'
2270+
}]
2271+
}, {
2272+
code: [
2273+
'class Hello extends React.Component {',
2274+
' renderStuff() {',
2275+
' const { name, ...rest } = this.props',
2276+
' return (<div {...rest}>{name}</div>);',
2277+
' }',
2278+
' render() {',
2279+
' this.renderStuff()',
2280+
' }',
2281+
'}',
2282+
'Hello.propTypes = {}'
2283+
].join('\n'),
2284+
errors: [{
2285+
message: '\'name\' is missing in props validation',
2286+
line: 3,
2287+
column: 13,
2288+
type: 'Property'
2289+
}]
22382290
}, {
22392291
code: [
22402292
'/** @extends React.Component */',

0 commit comments

Comments
 (0)