Skip to content

Commit deae58e

Browse files
committed
Add test cases
1 parent dd6f130 commit deae58e

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

tests/lib/rules/prop-types.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,44 @@ ruleTester.run('prop-types', rule, {
20302030
20312031
Slider.propTypes = RcSlider.propTypes;
20322032
`
2033+
},
2034+
{
2035+
code: `
2036+
class Foo extends React.Component {
2037+
bar() {
2038+
this.setState((state, props) => ({ current: props.current }));
2039+
}
2040+
render() {
2041+
return <div />;
2042+
}
2043+
}
2044+
2045+
Foo.propTypes = {
2046+
current: PropTypes.number.isRequired,
2047+
};
2048+
`
2049+
},
2050+
{
2051+
code: `
2052+
class Foo extends React.Component {
2053+
static getDerivedStateFromProps(props) {
2054+
const { foo } = props;
2055+
return {
2056+
foobar: foo
2057+
};
2058+
}
2059+
2060+
render() {
2061+
const { foobar } = this.state;
2062+
return <div>{foobar}</div>;
2063+
}
2064+
}
2065+
2066+
Foo.propTypes = {
2067+
foo: PropTypes.func.isRequired,
2068+
};
2069+
`,
2070+
settings: {react: {version: '16.3.0'}}
20332071
}
20342072
],
20352073

@@ -3851,6 +3889,50 @@ ruleTester.run('prop-types', rule, {
38513889
`,
38523890
errors: [{
38533891
message: '\'foo.baz\' is missing in props validation'
3892+
}],
3893+
},
3894+
{
3895+
code: `
3896+
class Foo extends React.Component {
3897+
bar() {
3898+
this.setState((state, props) => ({ current: props.current, bar: props.bar }));
3899+
}
3900+
render() {
3901+
return <div />;
3902+
}
3903+
}
3904+
3905+
Foo.propTypes = {
3906+
current: PropTypes.number.isRequired,
3907+
};
3908+
`,
3909+
errors: [{
3910+
message: '\'bar\' is missing in props validation'
3911+
}]
3912+
},
3913+
{
3914+
code: `
3915+
class Foo extends React.Component {
3916+
static getDerivedStateFromProps(props) {
3917+
const { foo, bar } = props;
3918+
return {
3919+
foobar: foo + bar
3920+
};
3921+
}
3922+
3923+
render() {
3924+
const { foobar } = this.state;
3925+
return <div>{foobar}</div>;
3926+
}
3927+
}
3928+
3929+
Foo.propTypes = {
3930+
foo: PropTypes.func.isRequired,
3931+
};
3932+
`,
3933+
settings: {react: {version: '16.3.0'}},
3934+
errors: [{
3935+
message: '\'bar\' is missing in props validation'
38543936
}]
38553937
},
38563938
{

0 commit comments

Comments
 (0)