Skip to content

Commit 09c4ed7

Browse files
committed
Add tests for {...} & Props in addition to Props & {...}
1 parent 357dcda commit 09c4ed7

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,23 @@ ruleTester.run('no-unused-prop-types', rule, {
888888
}
889889
`,
890890
parser: 'babel-eslint'
891+
}, {
892+
code: `
893+
type PropsB = { foo: string };
894+
type PropsC = { bar: string };
895+
type Props = {
896+
zap: string
897+
} & PropsB;
898+
899+
class Bar extends React.Component {
900+
props: Props & PropsC;
901+
902+
render() {
903+
return <div>{this.props.foo} - {this.props.bar} - {this.props.zap}</div>
904+
}
905+
}
906+
`,
907+
parser: 'babel-eslint'
891908
}, {
892909
code: [
893910
'import type Props from "fake";',
@@ -2831,6 +2848,26 @@ ruleTester.run('no-unused-prop-types', rule, {
28312848
{message: '\'zap\' PropType is defined but prop is never used'}
28322849
],
28332850
parser: 'babel-eslint'
2851+
}, {
2852+
code: `
2853+
type PropsB = { foo: string };
2854+
type PropsC = { bar: string };
2855+
type Props = {
2856+
zap: string
2857+
} & PropsB;
2858+
2859+
class Bar extends React.Component {
2860+
props: Props & PropsC;
2861+
2862+
render() {
2863+
return <div>{this.props.foo} - {this.props.bar}</div>
2864+
}
2865+
}
2866+
`,
2867+
errors: [
2868+
{message: '\'zap\' PropType is defined but prop is never used'}
2869+
],
2870+
parser: 'babel-eslint'
28342871
}, {
28352872
code: [
28362873
'class Hello extends React.Component {',

tests/lib/rules/prop-types.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,6 +1733,23 @@ ruleTester.run('prop-types', rule, {
17331733
}
17341734
`,
17351735
parser: 'babel-eslint'
1736+
}, {
1737+
code: `
1738+
type PropsA = { bar: string };
1739+
type PropsB = { zap: string };
1740+
type Props = {
1741+
baz: string
1742+
} & PropsA;
1743+
1744+
class Bar extends React.Component {
1745+
props: Props & PropsB;
1746+
1747+
render() {
1748+
return <div>{this.props.bar} - {this.props.zap} - {this.props.baz}</div>
1749+
}
1750+
}
1751+
`,
1752+
parser: 'babel-eslint'
17361753
}, {
17371754
code: `
17381755
type Props = { foo: string }
@@ -3463,6 +3480,26 @@ ruleTester.run('prop-types', rule, {
34633480
message: '\'fooBar\' is missing in props validation'
34643481
}],
34653482
parser: 'babel-eslint'
3483+
}, {
3484+
code: `
3485+
type PropsB = { bar: string };
3486+
type PropsC = { zap: string };
3487+
type Props = {
3488+
baz: string
3489+
} & PropsB;
3490+
3491+
class Bar extends React.Component {
3492+
props: Props & PropsC;
3493+
3494+
render() {
3495+
return <div>{this.props.bar} - {this.props.baz} - {this.props.fooBar}</div>
3496+
}
3497+
}
3498+
`,
3499+
errors: [{
3500+
message: '\'fooBar\' is missing in props validation'
3501+
}],
3502+
parser: 'babel-eslint'
34663503
}
34673504
]
34683505
});

0 commit comments

Comments
 (0)