diff --git a/lib/rules/prefer-find-by.ts b/lib/rules/prefer-find-by.ts index 460eab38..a5dc0eba 100644 --- a/lib/rules/prefer-find-by.ts +++ b/lib/rules/prefer-find-by.ts @@ -373,6 +373,10 @@ export default createTestingLibraryRule({ const callArguments = getQueryArguments(argument.body); const queryMethod = fullQueryMethod.split('By')[1]; + if (!queryMethod) { + return; + } + reportInvalidUsage(node, { queryMethod, queryVariant, diff --git a/tests/lib/rules/prefer-find-by.test.ts b/tests/lib/rules/prefer-find-by.test.ts index aaafdaef..909b58ca 100644 --- a/tests/lib/rules/prefer-find-by.test.ts +++ b/tests/lib/rules/prefer-find-by.test.ts @@ -149,6 +149,23 @@ ruleTester.run(RULE_NAME, rule, { }) `, }, + { + code: ` + import {screen, waitFor} from '@testing-library/foo'; + it('tests', async () => { + await waitFor(() => expect(screen.querySelector('baz')).toBeInTheDocument()); + }) + `, + }, + { + code: ` + import {waitFor} from '@testing-library/foo'; + it('tests', async () => { + const { container } = render() + await waitFor(() => expect(container.querySelector('baz')).toBeInTheDocument()); + }) + `, + }, ], invalid: [ ...createScenario((waitMethod: string, queryMethod: string) => ({