Skip to content

Commit fb614f7

Browse files
committed
test: add tests
1 parent 8344322 commit fb614f7

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/lib/rules/prefer-find-by.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,64 @@ ruleTester.run(RULE_NAME, rule, {
691691
})
692692
`,
693693
})),
694+
...createScenario((waitMethod, queryMethod) => ({
695+
code: `
696+
import { screen } from '${testingFramework}';
697+
698+
it('tests', async () => {
699+
await ${waitMethod}(() => expect(screen.${queryMethod}('button', { name: 'Count is: 0' })).toBeInTheDocument())
700+
})
701+
`,
702+
errors: [
703+
{
704+
line: 5,
705+
column: 11,
706+
messageId: 'preferFindBy',
707+
data: {
708+
queryVariant: getFindByQueryVariant(queryMethod),
709+
queryMethod: queryMethod.split('By')[1],
710+
prevQuery: queryMethod,
711+
waitForMethodName: waitMethod,
712+
},
713+
},
714+
],
715+
output: `
716+
import { screen } from '${testingFramework}';
717+
718+
it('tests', async () => {
719+
expect(await screen.${buildFindByMethod(queryMethod)}('button', { name: 'Count is: 0' })).toBeInTheDocument()
720+
})
721+
`,
722+
})),
723+
...createScenario((waitMethod, queryMethod) => ({
724+
code: `
725+
import { screen } from '${testingFramework}';
726+
727+
it('tests', async () => {
728+
await ${waitMethod}(() => expect(screen.${queryMethod}('button', { name: 'Count is: 0' })).toBeInTheDocument(), { timeout: 100, interval: 200 })
729+
})
730+
`,
731+
errors: [
732+
{
733+
line: 5,
734+
column: 11,
735+
messageId: 'preferFindBy',
736+
data: {
737+
queryVariant: getFindByQueryVariant(queryMethod),
738+
queryMethod: queryMethod.split('By')[1],
739+
prevQuery: queryMethod,
740+
waitForMethodName: waitMethod,
741+
},
742+
},
743+
],
744+
output: `
745+
import { screen } from '${testingFramework}';
746+
747+
it('tests', async () => {
748+
expect(await screen.${buildFindByMethod(queryMethod)}('button', { name: 'Count is: 0' }, { timeout: 100, interval: 200 })).toBeInTheDocument()
749+
})
750+
`,
751+
})),
694752
// Issue #579, https://github.com/testing-library/eslint-plugin-testing-library/issues/579
695753
// findBy can have two sets of options: await screen.findByText('text', queryOptions, waitForOptions)
696754
...createScenario((waitMethod, queryMethod) => ({

0 commit comments

Comments
 (0)