Skip to content

Commit 1364182

Browse files
committed
test(no-await-sync-query): use more realistic scenarios
1 parent 19fbcf3 commit 1364182

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

tests/lib/rules/no-await-sync-query.test.ts

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,22 @@ ruleTester.run(RULE_NAME, rule, {
1313
// sync queries without await are valid
1414
...SYNC_QUERIES_COMBINATIONS.map((query) => ({
1515
code: `() => {
16-
${query}('foo')
16+
const element = ${query}('foo')
17+
}
18+
`,
19+
})),
20+
// sync queries without await inside assert are valid
21+
...SYNC_QUERIES_COMBINATIONS.map((query) => ({
22+
code: `() => {
23+
expect(${query}('foo')).toBeEnabled()
1724
}
1825
`,
1926
})),
2027

2128
// async queries with await operator are valid
2229
...ASYNC_QUERIES_COMBINATIONS.map((query) => ({
2330
code: `async () => {
24-
await ${query}('foo')
31+
const element = await ${query}('foo')
2532
}
2633
`,
2734
})),
@@ -40,29 +47,58 @@ ruleTester.run(RULE_NAME, rule, {
4047
// sync queries with await operator are not valid
4148
...SYNC_QUERIES_COMBINATIONS.map((query) => ({
4249
code: `async () => {
43-
await ${query}('foo')
50+
const element = await ${query}('foo')
51+
}
52+
`,
53+
errors: [
54+
{
55+
messageId: 'noAwaitSyncQuery',
56+
line: 2,
57+
column: 31,
58+
},
59+
],
60+
})),
61+
// sync queries with await operator inside assert are not valid
62+
...SYNC_QUERIES_COMBINATIONS.map((query) => ({
63+
code: `async () => {
64+
expect(await ${query}('foo')).toBeEnabled()
4465
}
4566
`,
4667
errors: [
4768
{
4869
messageId: 'noAwaitSyncQuery',
4970
line: 2,
50-
column: 15,
71+
column: 22,
5172
},
5273
],
5374
})),
5475

5576
// sync queries in screen with await operator are not valid
5677
...SYNC_QUERIES_COMBINATIONS.map((query) => ({
5778
code: `async () => {
58-
await screen.${query}('foo')
79+
const element = await screen.${query}('foo')
5980
}
6081
`,
6182
errors: [
6283
{
6384
messageId: 'noAwaitSyncQuery',
6485
line: 2,
65-
column: 22,
86+
column: 38,
87+
},
88+
],
89+
})),
90+
91+
// sync queries in screen with await operator inside assert are not valid
92+
...SYNC_QUERIES_COMBINATIONS.map((query) => ({
93+
code: `async () => {
94+
expect(await screen.${query}('foo')).toBeEnabled()
95+
}
96+
`,
97+
errors: [
98+
{
99+
messageId: 'noAwaitSyncQuery',
100+
line: 2,
101+
column: 29,
66102
},
67103
],
68104
})),

0 commit comments

Comments
 (0)