Skip to content

Commit e5f13f4

Browse files
committed
[Tests] prop-types: add passing test
Closes #1090
1 parent 1cca82f commit e5f13f4

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

tests/lib/rules/prop-types.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3608,7 +3608,7 @@ ruleTester.run('prop-types', rule, {
36083608
{
36093609
code: `
36103610
import React, { forwardRef } from "react";
3611-
3611+
36123612
export type Props = { children: React.ReactNode; type: "submit" | "button" };
36133613
36143614
export const FancyButton = forwardRef<HTMLButtonElement, Props>((props, ref) => (
@@ -3681,7 +3681,7 @@ ruleTester.run('prop-types', rule, {
36813681
label: string,
36823682
disabled?: boolean
36833683
} & {};
3684-
3684+
36853685
const Button: React.FC<ButtonProps> = ({ children, icon, label, disabled }: ButtonProps) => {
36863686
return <div />;
36873687
}
@@ -3696,11 +3696,11 @@ ruleTester.run('prop-types', rule, {
36963696
const {baz} = Foo
36973697
return <div>{baz} {bar}</div>
36983698
}
3699-
3699+
37003700
Foo.propTypes = {
37013701
bar: PropTypes.string.isRequired,
37023702
}
3703-
3703+
37043704
Foo.baz = 'hi'
37053705
`,
37063706
},
@@ -3710,14 +3710,42 @@ ruleTester.run('prop-types', rule, {
37103710
type Props = {
37113711
'data-hover': string
37123712
}
3713-
3713+
37143714
function MyComponent({
37153715
'data-hover': dataHover
37163716
}: Props) {
37173717
return <span data-hover={dataHover} />
37183718
}
37193719
`,
37203720
features: ['types'],
3721+
},
3722+
{
3723+
code: `
3724+
import React, { PropTypes } from 'react';
3725+
3726+
function MyComponent({ name }) {
3727+
const someParams = {
3728+
userName: name,
3729+
greeting: 'Hi there',
3730+
};
3731+
3732+
function getMessage({ userName, greeting }) {
3733+
return <span>\`\${greeting} \${userName}\`</span>;
3734+
}
3735+
3736+
return (
3737+
<div>
3738+
{ getMessage(someParams) }
3739+
</div>
3740+
);
3741+
}
3742+
3743+
MyComponent.propTypes = {
3744+
name: PropTypes.string.isRequired,
3745+
};
3746+
3747+
export default MyComponent;
3748+
`,
37213749
}
37223750
)),
37233751

@@ -7494,7 +7522,7 @@ ruleTester.run('prop-types', rule, {
74947522
{
74957523
code: `
74967524
import React, { forwardRef } from "react";
7497-
7525+
74987526
export type Props = { children: React.ReactNode; type: "submit" | "button" };
74997527
75007528
export const FancyButton = forwardRef<HTMLButtonElement, Props>((props, ref) => (
@@ -7514,7 +7542,7 @@ ruleTester.run('prop-types', rule, {
75147542
{
75157543
code: `
75167544
import React, { forwardRef } from "react";
7517-
7545+
75187546
export interface IProps { children: React.ReactNode; type: "submit" | "button" };
75197547
75207548
export const FancyButton = forwardRef<HTMLButtonElement, IProps>((props, ref) => (

0 commit comments

Comments
 (0)