From abbb70c0993d42349e1c2b7208286b92da2a7cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Beltr=C3=A1n=20Alarc=C3=B3n?= Date: Sun, 3 Apr 2022 18:19:58 +0200 Subject: [PATCH 1/2] fix(no-global-regexp-flag-in-query): check if empty name property node --- lib/rules/no-global-regexp-flag-in-query.ts | 7 +++++-- .../rules/no-global-regexp-flag-in-query.test.ts | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/rules/no-global-regexp-flag-in-query.ts b/lib/rules/no-global-regexp-flag-in-query.ts index 6f8683f8..13ef6d41 100644 --- a/lib/rules/no-global-regexp-flag-in-query.ts +++ b/lib/rules/no-global-regexp-flag-in-query.ts @@ -96,8 +96,11 @@ export default createTestingLibraryRule({ ASTUtils.isIdentifier(p.key) && p.key.name === 'name' && isLiteral(p.value) - ) as TSESTree.ObjectLiteralElement & { value: TSESTree.Literal }; - report(namePropertyNode.value); + ) as TSESTree.Property | undefined; + + if (namePropertyNode) { + report(namePropertyNode.value); + } } }, }; diff --git a/tests/lib/rules/no-global-regexp-flag-in-query.test.ts b/tests/lib/rules/no-global-regexp-flag-in-query.test.ts index df26b365..f3bd59df 100644 --- a/tests/lib/rules/no-global-regexp-flag-in-query.test.ts +++ b/tests/lib/rules/no-global-regexp-flag-in-query.test.ts @@ -78,6 +78,19 @@ ruleTester.run(RULE_NAME, rule, { const utils = render() utils.notAQuery(/hello/i) `, + + // issue #565 + { + code: ` + import { screen } from "@testing-library/react" + + describe("App", () => { + test("is rendered", async () => { + await screen.findByText("Hello World", { exact: false }); + }) + }) + `, + }, ], invalid: [ { From 9d151215038670811f0910cce3c42e8b0e55f2b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Beltr=C3=A1n=20Alarc=C3=B3n?= Date: Mon, 4 Apr 2022 11:16:56 +0200 Subject: [PATCH 2/2] style: write the valid snippet without an object --- tests/lib/rules/no-global-regexp-flag-in-query.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/lib/rules/no-global-regexp-flag-in-query.test.ts b/tests/lib/rules/no-global-regexp-flag-in-query.test.ts index f3bd59df..9762994e 100644 --- a/tests/lib/rules/no-global-regexp-flag-in-query.test.ts +++ b/tests/lib/rules/no-global-regexp-flag-in-query.test.ts @@ -80,8 +80,7 @@ ruleTester.run(RULE_NAME, rule, { `, // issue #565 - { - code: ` + ` import { screen } from "@testing-library/react" describe("App", () => { @@ -90,7 +89,6 @@ ruleTester.run(RULE_NAME, rule, { }) }) `, - }, ], invalid: [ {