Skip to content

Commit

Permalink
Add tests for {...} & Props in addition to Props & {...}
Browse files Browse the repository at this point in the history
  • Loading branch information
jseminck committed Sep 8, 2017
1 parent 357dcda commit 09c4ed7
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,23 @@ ruleTester.run('no-unused-prop-types', rule, {
}
`,
parser: 'babel-eslint'
}, {
code: `
type PropsB = { foo: string };
type PropsC = { bar: string };
type Props = {
zap: string
} & PropsB;
class Bar extends React.Component {
props: Props & PropsC;
render() {
return <div>{this.props.foo} - {this.props.bar} - {this.props.zap}</div>
}
}
`,
parser: 'babel-eslint'
}, {
code: [
'import type Props from "fake";',
Expand Down Expand Up @@ -2831,6 +2848,26 @@ ruleTester.run('no-unused-prop-types', rule, {
{message: '\'zap\' PropType is defined but prop is never used'}
],
parser: 'babel-eslint'
}, {
code: `
type PropsB = { foo: string };
type PropsC = { bar: string };
type Props = {
zap: string
} & PropsB;
class Bar extends React.Component {
props: Props & PropsC;
render() {
return <div>{this.props.foo} - {this.props.bar}</div>
}
}
`,
errors: [
{message: '\'zap\' PropType is defined but prop is never used'}
],
parser: 'babel-eslint'
}, {
code: [
'class Hello extends React.Component {',
Expand Down
37 changes: 37 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,23 @@ ruleTester.run('prop-types', rule, {
}
`,
parser: 'babel-eslint'
}, {
code: `
type PropsA = { bar: string };
type PropsB = { zap: string };
type Props = {
baz: string
} & PropsA;
class Bar extends React.Component {
props: Props & PropsB;
render() {
return <div>{this.props.bar} - {this.props.zap} - {this.props.baz}</div>
}
}
`,
parser: 'babel-eslint'
}, {
code: `
type Props = { foo: string }
Expand Down Expand Up @@ -3463,6 +3480,26 @@ ruleTester.run('prop-types', rule, {
message: '\'fooBar\' is missing in props validation'
}],
parser: 'babel-eslint'
}, {
code: `
type PropsB = { bar: string };
type PropsC = { zap: string };
type Props = {
baz: string
} & PropsB;
class Bar extends React.Component {
props: Props & PropsC;
render() {
return <div>{this.props.bar} - {this.props.baz} - {this.props.fooBar}</div>
}
}
`,
errors: [{
message: '\'fooBar\' is missing in props validation'
}],
parser: 'babel-eslint'
}
]
});

0 comments on commit 09c4ed7

Please sign in to comment.