Skip to content

Commit 2930e92

Browse files
committed
test: add tests
1 parent 06443b8 commit 2930e92

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ ruleTester.run(RULE_NAME, rule, {
149149
column: 31,
150150
},
151151
],
152+
output: `async () => {
153+
const element = ${query}('foo')
154+
}
155+
`,
152156
})),
153157
// custom sync queries with await operator are not valid
154158
{
@@ -158,6 +162,11 @@ ruleTester.run(RULE_NAME, rule, {
158162
}
159163
`,
160164
errors: [{ messageId: 'noAwaitSyncQuery', line: 3, column: 31 }],
165+
output: `
166+
async () => {
167+
const element = getByIcon('search')
168+
}
169+
`,
161170
},
162171
{
163172
code: `
@@ -166,6 +175,11 @@ ruleTester.run(RULE_NAME, rule, {
166175
}
167176
`,
168177
errors: [{ messageId: 'noAwaitSyncQuery', line: 3, column: 31 }],
178+
output: `
179+
async () => {
180+
const element = queryByIcon('search')
181+
}
182+
`,
169183
},
170184
{
171185
code: `
@@ -174,6 +188,11 @@ ruleTester.run(RULE_NAME, rule, {
174188
}
175189
`,
176190
errors: [{ messageId: 'noAwaitSyncQuery', line: 3, column: 38 }],
191+
output: `
192+
async () => {
193+
const element = screen.getAllByIcon('search')
194+
}
195+
`,
177196
},
178197
{
179198
code: `
@@ -182,6 +201,11 @@ ruleTester.run(RULE_NAME, rule, {
182201
}
183202
`,
184203
errors: [{ messageId: 'noAwaitSyncQuery', line: 3, column: 38 }],
204+
output: `
205+
async () => {
206+
const element = screen.queryAllByIcon('search')
207+
}
208+
`,
185209
},
186210
// sync queries with await operator inside assert are not valid
187211
...SYNC_QUERIES_COMBINATIONS.map<RuleInvalidTestCase>((query) => ({
@@ -196,6 +220,10 @@ ruleTester.run(RULE_NAME, rule, {
196220
column: 22,
197221
},
198222
],
223+
output: `async () => {
224+
expect( ${query}('foo')).toBeEnabled()
225+
}
226+
`,
199227
})),
200228

201229
// sync queries in screen with await operator are not valid
@@ -211,6 +239,10 @@ ruleTester.run(RULE_NAME, rule, {
211239
column: 38,
212240
},
213241
],
242+
output: `async () => {
243+
const element = screen.${query}('foo')
244+
}
245+
`,
214246
})),
215247

216248
// sync queries in screen with await operator inside assert are not valid
@@ -226,6 +258,10 @@ ruleTester.run(RULE_NAME, rule, {
226258
column: 29,
227259
},
228260
],
261+
output: `async () => {
262+
expect( screen.${query}('foo')).toBeEnabled()
263+
}
264+
`,
229265
})),
230266

231267
// sync query awaited and related to testing library module
@@ -240,6 +276,12 @@ ruleTester.run(RULE_NAME, rule, {
240276
}
241277
`,
242278
errors: [{ messageId: 'noAwaitSyncQuery', line: 4, column: 38 }],
279+
output: `
280+
import { screen } from '${testingFramework}'
281+
() => {
282+
const element = screen.getByRole('button')
283+
}
284+
`,
243285
})
244286
),
245287
// sync query awaited and related to custom module is not valid
@@ -252,6 +294,12 @@ ruleTester.run(RULE_NAME, rule, {
252294
}
253295
`,
254296
errors: [{ messageId: 'noAwaitSyncQuery', line: 4, column: 38 }],
297+
output: `
298+
import { screen } from 'test-utils'
299+
() => {
300+
const element = screen.getByRole('button')
301+
}
302+
`,
255303
},
256304

257305
// awaited custom sync query matching custom-queries setting is invalid
@@ -265,6 +313,24 @@ ruleTester.run(RULE_NAME, rule, {
265313
})
266314
`,
267315
errors: [{ messageId: 'noAwaitSyncQuery', line: 3, column: 31 }],
316+
output: `
317+
test('A valid example test', async () => {
318+
const element = queryByIcon('search')
319+
})
320+
`,
321+
},
322+
{
323+
code: `
324+
test('A valid example test', async () => {
325+
const element = await(screen.getByRole('button'))
326+
})
327+
`,
328+
errors: [{ messageId: 'noAwaitSyncQuery', line: 3, column: 38 }],
329+
output: `
330+
test('A valid example test', async () => {
331+
const element = (screen.getByRole('button'))
332+
})
333+
`,
268334
},
269335
],
270336
});

0 commit comments

Comments
 (0)