Skip to content

Commit

Permalink
Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzherdev committed Aug 19, 2018
1 parent b24d60e commit 35f717c
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions tests/lib/rules/prop-types.js
Expand Up @@ -1957,6 +1957,44 @@ ruleTester.run('prop-types', rule, {
Slider.propTypes = RcSlider.propTypes;
`
},
{
code: `
class Foo extends React.Component {
bar() {
this.setState((state, props) => ({ current: props.current }));
}
render() {
return <div />;
}
}
Foo.propTypes = {
current: PropTypes.number.isRequired,
};
`
},
{
code: `
class Foo extends React.Component {
static getDerivedStateFromProps(props) {
const { foo } = props;
return {
foobar: foo
};
}
render() {
const { foobar } = this.state;
return <div>{foobar}</div>;
}
}
Foo.propTypes = {
foo: PropTypes.func.isRequired,
};
`,
settings: {react: {version: '16.3.0'}}
}
],

Expand Down Expand Up @@ -3760,6 +3798,50 @@ ruleTester.run('prop-types', rule, {
message: '\'bad\' is missing in props validation'
}],
parser: 'babel-eslint'
},
{
code: `
class Foo extends React.Component {
bar() {
this.setState((state, props) => ({ current: props.current, bar: props.bar }));
}
render() {
return <div />;
}
}
Foo.propTypes = {
current: PropTypes.number.isRequired,
};
`,
errors: [{
message: '\'bar\' is missing in props validation'
}]
},
{
code: `
class Foo extends React.Component {
static getDerivedStateFromProps(props) {
const { foo, bar } = props;
return {
foobar: foo + bar
};
}
render() {
const { foobar } = this.state;
return <div>{foobar}</div>;
}
}
Foo.propTypes = {
foo: PropTypes.func.isRequired,
};
`,
settings: {react: {version: '16.3.0'}},
errors: [{
message: '\'bar\' is missing in props validation'
}]
}
]
});

0 comments on commit 35f717c

Please sign in to comment.