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..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 @@ -78,6 +78,17 @@ ruleTester.run(RULE_NAME, rule, { const utils = render() utils.notAQuery(/hello/i) `, + + // issue #565 + ` + import { screen } from "@testing-library/react" + + describe("App", () => { + test("is rendered", async () => { + await screen.findByText("Hello World", { exact: false }); + }) + }) + `, ], invalid: [ {