Skip to content

Commit

Permalink
fix(prefer-find-by): avoid reporting querySelector (#538)
Browse files Browse the repository at this point in the history
* fix(prefer-find-by): fix report with querySelector

Fix #501

* fixup! fix(prefer-find-by): fix report with querySelector
  • Loading branch information
bpinto authored Jan 21, 2022
1 parent a6d4cda commit 369e24f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/prefer-find-by.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ export default createTestingLibraryRule<Options, MessageIds>({
const callArguments = getQueryArguments(argument.body);
const queryMethod = fullQueryMethod.split('By')[1];

if (!queryMethod) {
return;
}

reportInvalidUsage(node, {
queryMethod,
queryVariant,
Expand Down
17 changes: 17 additions & 0 deletions tests/lib/rules/prefer-find-by.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ({
Expand Down

0 comments on commit 369e24f

Please sign in to comment.