Skip to content

Commit efbb8a5

Browse files
committed
Add more tests for no-this-in-sfc
1 parent db5a243 commit efbb8a5

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/lib/rules/no-this-in-sfc.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,35 @@ ruleTester.run('no-this-in-sfc', rule, {
7171
}
7272
}
7373
`
74+
}, {
75+
code: `
76+
function Foo(props) {
77+
return props.foo ? <span>{props.bar}</span> : null;
78+
}`
79+
}, {
80+
code: `
81+
function Foo(props) {
82+
if (props.foo) {
83+
return <div>{props.bar}</div>;
84+
}
85+
return null;
86+
}`
87+
}, {
88+
code: `
89+
function Foo(props) {
90+
if (props.foo) {
91+
something();
92+
}
93+
return null;
94+
}`
95+
}, {
96+
code: 'const Foo = (props) => <span>{props.foo}</span>'
97+
}, {
98+
code: 'const Foo = ({ foo }) => <span>{foo}</span>'
99+
}, {
100+
code: 'const Foo = (props) => props.foo ? <span>{props.bar}</span> : null;'
101+
}, {
102+
code: 'const Foo = ({ foo, bar }) => foo ? <span>{bar}</span> : null;'
74103
}],
75104
invalid: [{
76105
code: `
@@ -98,6 +127,36 @@ ruleTester.run('no-this-in-sfc', rule, {
98127
return <div>{foo}</div>;
99128
}`,
100129
errors: [{message: ERROR_MESSAGE}]
130+
}, {
131+
code: `
132+
function Foo(props) {
133+
return props.foo ? <div>{this.props.bar}</div> : null;
134+
}`,
135+
errors: [{message: ERROR_MESSAGE}]
136+
}, {
137+
code: `
138+
function Foo(props) {
139+
if (props.foo) {
140+
return <div>{this.props.bar}</div>;
141+
}
142+
return null;
143+
}`,
144+
errors: [{message: ERROR_MESSAGE}]
145+
}, {
146+
code: `
147+
function Foo(props) {
148+
if (this.props.foo) {
149+
something();
150+
}
151+
return null;
152+
}`,
153+
errors: [{message: ERROR_MESSAGE}]
154+
}, {
155+
code: 'const Foo = (props) => <span>{this.props.foo}</span>',
156+
errors: [{message: ERROR_MESSAGE}]
157+
}, {
158+
code: 'const Foo = (props) => this.props.foo ? <span>{props.bar}</span> : null;',
159+
errors: [{message: ERROR_MESSAGE}]
101160
}, {
102161
code: `
103162
function Foo(props) {

0 commit comments

Comments
 (0)