Skip to content

Commit 23121e0

Browse files
TildaDaresljharb
authored andcommitted
[Tests] function-component-definition: add passing test cases
Closes #3057
1 parent d000f8c commit 23121e0

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
3434
* [readme] remove dead codeclimate badge, add actions badge (@ljharb)
3535
* [readme] Remove dead david-dm badge ([#3262][] @ddzz)
3636
* [Refactor] [`jsx-closing-bracket-location`], [`jsx-no-bind`]: fix eslint issues ([#3351][] @caroline223)
37+
* [Tests] [`function-component-definition`]: add passing test cases ([#3355][] @TildaDares)
3738

39+
[#3355]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3355
3840
[#3353]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3353
3941
[#3351]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3351
4042
[#3350]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3350

tests/lib/rules/function-component-definition.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,45 @@ ruleTester.run('function-component-definition', rule, {
406406
`,
407407
options: [{ unnamedComponents: ['arrow-function', 'function-expression'] }],
408408
},
409+
{
410+
// should not report non-jsx components
411+
code: `
412+
export default (key, subTree = {}) => {
413+
return (state) => {
414+
const dataInStore = getFromDataModel(key)(state);
415+
const fullPaths = dataInStore.map((item, index) => {
416+
return [key, index];
417+
});
418+
419+
return {
420+
key,
421+
paths: fullPaths.map((p) => [p[1]]),
422+
fullPaths,
423+
subTree: Object.keys(subTree).length ? subTree : null,
424+
}
425+
};
426+
}
427+
`,
428+
},
429+
{
430+
// should not report non-jsx components
431+
code: `
432+
function mapStateToProps() {
433+
const internItems = makeInternArray();
434+
const internClassList = makeInternArray();
435+
436+
return (state, props) => {
437+
const { store, bucket, singleCharacter } = props;
438+
439+
return {
440+
store: null,
441+
destinyVersion: store.destinyVersion,
442+
storeId: store.id,
443+
}
444+
}
445+
}
446+
`,
447+
},
409448
]),
410449

411450
invalid: parsers.all([

0 commit comments

Comments
 (0)