Skip to content

Commit

Permalink
test(rules): add tests to varios rules to check improved function com…
Browse files Browse the repository at this point in the history
…ponent detection
  • Loading branch information
jzabala committed Jul 8, 2020
1 parent 4689be2 commit 1811a0e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
26 changes: 26 additions & 0 deletions tests/lib/rules/function-component-definition.js
Expand Up @@ -68,6 +68,32 @@ ruleTester.run('function-component-definition', rule, {
}, {
code: 'var Foo = React.memo(function Foo() { return <p/> })',
options: [{namedComponents: 'function-declaration'}]
}, {
// shouldn't trigger this rule since functions stating with a lowercase
// letter are not considered components
code: `
const selectAvatarByUserId = (state, id) => {
const user = selectUserById(state, id)
return null
}
`,
options: [{namedComponents: 'function-declaration'}]
}, {
// shouldn't trigger this rule since functions stating with a lowercase
// letter are not considered components
code: `
function ensureValidSourceType(sourceType: string) {
switch (sourceType) {
case 'ALBUM':
case 'PLAYLIST':
return sourceType;
default:
return null;
}
}
`,
options: [{namedComponents: 'arrow-function'}],
parser: parsers.TYPESCRIPT_ESLINT
}, {
code: 'function Hello(props: Test) { return <p/> }',
options: [{namedComponents: 'function-declaration'}],
Expand Down
22 changes: 21 additions & 1 deletion tests/lib/rules/prop-types.js
Expand Up @@ -2504,7 +2504,27 @@ ruleTester.run('prop-types', rule, {
}
`,
parser: parsers.TYPESCRIPT_ESLINT
}
},
// shouldn't trigger this rule since functions stating with a lowercase
// letter are not considered components
`
function noAComponent(props) {
return <div>{props.text}</div>
}
`,
// shouldn't trigger this rule for 'render' since functions stating with a lowercase
// letter are not considered components
`
const MyComponent = (props) => {
const render = () => {
return <test>{props.hello}</test>;
}
return render();
};
MyComponent.propTypes = {
hello: PropTypes.string.isRequired,
};
`
],

invalid: [
Expand Down

0 comments on commit 1811a0e

Please sign in to comment.