Skip to content

Commit c107636

Browse files
committed
Add unit tests
1 parent d14ffb4 commit c107636

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/lib/rules/prop-types.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,19 @@ ruleTester.run('prop-types', rule, {
13851385
'}'
13861386
].join('\n'),
13871387
parser: 'babel-eslint'
1388+
}, {
1389+
// Flow annotations with variance
1390+
code: [
1391+
'type Props = {',
1392+
' +firstname: string;',
1393+
' -lastname: string;',
1394+
'};',
1395+
'function Hello(props: Props): React.Element {',
1396+
' const {firstname, lastname} = props;',
1397+
' return <div>Hello {firstname} {lastname}</div>',
1398+
'}'
1399+
].join('\n'),
1400+
parser: 'babel-eslint'
13881401
}
13891402
],
13901403

@@ -2471,6 +2484,52 @@ ruleTester.run('prop-types', rule, {
24712484
line: 3,
24722485
column: 29
24732486
}]
2487+
}, {
2488+
code: [
2489+
'type MyComponentProps = {',
2490+
' +a: number,',
2491+
'};',
2492+
'function MyComponent({ a, b }: MyComponentProps) {',
2493+
' return <div />;',
2494+
'}'
2495+
].join('\n'),
2496+
parser: 'babel-eslint',
2497+
errors: [{
2498+
message: '\'b\' is missing in props validation',
2499+
line: 4,
2500+
column: 27,
2501+
type: 'Property'
2502+
}]
2503+
}, {
2504+
code: [
2505+
'type MyComponentProps = {',
2506+
' -a: number,',
2507+
'};',
2508+
'function MyComponent({ a, b }: MyComponentProps) {',
2509+
' return <div />;',
2510+
'}'
2511+
].join('\n'),
2512+
parser: 'babel-eslint',
2513+
errors: [{
2514+
message: '\'b\' is missing in props validation',
2515+
line: 4,
2516+
column: 27,
2517+
type: 'Property'
2518+
}]
2519+
}, {
2520+
code: [
2521+
'type Props = {+name: Object;};',
2522+
'class Hello extends React.Component {',
2523+
' props: Props;',
2524+
' render () {',
2525+
' return <div>Hello {this.props.firstname}</div>;',
2526+
' }',
2527+
'}'
2528+
].join('\n'),
2529+
parser: 'babel-eslint',
2530+
errors: [
2531+
{message: '\'firstname\' is missing in props validation'}
2532+
]
24742533
}
24752534
]
24762535
});

0 commit comments

Comments
 (0)