From 81edb3ed0fc452113ee0219c43750c1a3aa10f88 Mon Sep 17 00:00:00 2001 From: Senja Jarva Date: Sun, 23 Oct 2022 17:51:32 +0300 Subject: [PATCH 1/2] fix(no-node-access): document more valid test cases These examples were gotten from discussions in issue #386 --- tests/lib/rules/no-node-access.test.ts | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/lib/rules/no-node-access.test.ts b/tests/lib/rules/no-node-access.test.ts index 717fdcac..6d4cb40e 100644 --- a/tests/lib/rules/no-node-access.test.ts +++ b/tests/lib/rules/no-node-access.test.ts @@ -138,6 +138,44 @@ ruleTester.run(RULE_NAME, rule, { expect(container.firstChild).toMatchSnapshot() `, }, + { + // Example from discussions in issue #386 + code: ` + import { render } from '@testing-library/react'; + + function Wrapper(props) { + // this should NOT be reported + if (props.children) { + // ... + } + + // this should NOT be reported + return
{props.children}
+ }; + + render(); + expect(screen.getByText('SomeComponent')).toBeInTheDocument(); + `, + }, + { + // Example from discussions in issue #386 + code: ` + import { render } from '@testing-library/react'; + + function Wrapper({ children }) { + // this should NOT be reported + if (children) { + // ... + } + + // this should NOT be reported + return
{children}
+ }; + + render(); + expect(screen.getByText('SomeComponent')).toBeInTheDocument(); + `, + }, ] ), invalid: SUPPORTED_TESTING_FRAMEWORKS.flatMap((testingFramework) => [ From e42d0f0bf78491ea8a3d0177f26cd4eeee5d31e3 Mon Sep 17 00:00:00 2001 From: Senja Jarva Date: Sun, 23 Oct 2022 18:00:14 +0300 Subject: [PATCH 2/2] fix(no-node-access): remove redundant unit test --- tests/lib/rules/no-node-access.test.ts | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/tests/lib/rules/no-node-access.test.ts b/tests/lib/rules/no-node-access.test.ts index 6d4cb40e..e15bc727 100644 --- a/tests/lib/rules/no-node-access.test.ts +++ b/tests/lib/rules/no-node-access.test.ts @@ -143,25 +143,6 @@ ruleTester.run(RULE_NAME, rule, { code: ` import { render } from '@testing-library/react'; - function Wrapper(props) { - // this should NOT be reported - if (props.children) { - // ... - } - - // this should NOT be reported - return
{props.children}
- }; - - render(); - expect(screen.getByText('SomeComponent')).toBeInTheDocument(); - `, - }, - { - // Example from discussions in issue #386 - code: ` - import { render } from '@testing-library/react'; - function Wrapper({ children }) { // this should NOT be reported if (children) {