@@ -257,73 +257,126 @@ ruleTester.run(RULE_NAME, rule, {
257
257
] ,
258
258
259
259
invalid : [
260
- // async queries without await operator or then method are not valid
261
- ...createTestCase ( ( query ) => ( {
262
- code : `
260
+ ...ALL_ASYNC_COMBINATIONS_TO_TEST . map (
261
+ ( query ) =>
262
+ ( {
263
+ code : `// async queries without await operator or then method are not valid
264
+ import { render } from '@testing-library/react'
265
+
266
+ test("An example test", async () => {
263
267
doSomething()
264
268
const foo = ${ query } ('foo')
269
+ });
265
270
` ,
266
- errors : [ { messageId : 'awaitAsyncQuery' , line : 6 , column : 21 } ] ,
267
- } ) ) ,
271
+ errors : [ { messageId : 'awaitAsyncQuery' , line : 6 , column : 21 } ] ,
272
+ } as const )
273
+ ) ,
274
+ ...ALL_ASYNC_COMBINATIONS_TO_TEST . map (
275
+ ( query ) =>
276
+ ( {
277
+ code : `// async screen queries without await operator or then method are not valid
278
+ import { render } from '@testing-library/react'
279
+
280
+ test("An example test", async () => {
281
+ screen.${ query } ('foo')
282
+ });
283
+ ` ,
284
+ errors : [
285
+ {
286
+ messageId : 'awaitAsyncQuery' ,
287
+ line : 5 ,
288
+ column : 16 ,
289
+ data : { name : query } ,
290
+ } ,
291
+ ] ,
292
+ } as const )
293
+ ) ,
294
+ ...ALL_ASYNC_COMBINATIONS_TO_TEST . map (
295
+ ( query ) =>
296
+ ( {
297
+ code : `
298
+ import { render } from '@testing-library/react'
268
299
269
- // async screen queries without await operator or then method are not valid
270
- ...createTestCase ( ( query ) => ( {
271
- code : `screen.${ query } ('foo')` ,
272
- errors : [ { messageId : 'awaitAsyncQuery' , line : 4 , column : 14 } ] ,
273
- } ) ) ,
300
+ test("An example test", async () => {
301
+ doSomething()
302
+ const foo = ${ query } ('foo')
303
+ });
304
+ ` ,
305
+ errors : [
306
+ {
307
+ messageId : 'awaitAsyncQuery' ,
308
+ line : 6 ,
309
+ column : 21 ,
310
+ data : { name : query } ,
311
+ } ,
312
+ ] ,
313
+ } as const )
314
+ ) ,
315
+ ...ALL_ASYNC_COMBINATIONS_TO_TEST . map (
316
+ ( query ) =>
317
+ ( {
318
+ code : `
319
+ import { render } from '@testing-library/react'
274
320
275
- ...createTestCase ( ( query ) => ( {
276
- code : `
321
+ test("An example test", async () => {
277
322
const foo = ${ query } ('foo')
278
323
expect(foo).toBeInTheDocument()
279
324
expect(foo).toHaveAttribute('src', 'bar');
325
+ });
280
326
` ,
281
- errors : [
282
- {
283
- line : 5 ,
284
- column : 21 ,
285
- messageId : 'awaitAsyncQuery' ,
286
- data : {
287
- name : query ,
288
- } ,
289
- } ,
290
- ] ,
291
- } ) ) ,
327
+ errors : [
328
+ {
329
+ messageId : 'awaitAsyncQuery' ,
330
+ line : 5 ,
331
+ column : 21 ,
332
+ data : { name : query } ,
333
+ } ,
334
+ ] ,
335
+ } as const )
336
+ ) ,
292
337
293
338
// unresolved async queries are not valid (aggressive reporting)
294
- ...ALL_ASYNC_COMBINATIONS_TO_TEST . map ( ( query ) => ( {
295
- code : `
339
+ ...ALL_ASYNC_COMBINATIONS_TO_TEST . map (
340
+ ( query ) =>
341
+ ( {
342
+ code : `
296
343
import { render } from "another-library"
297
344
298
345
test('An example test', async () => {
299
346
const example = ${ query } ("my example")
300
347
})
301
348
` ,
302
- errors : [ { messageId : 'awaitAsyncQuery' , line : 5 , column : 27 } ] ,
303
- } ) ) ,
349
+ errors : [ { messageId : 'awaitAsyncQuery' , line : 5 , column : 27 } ] ,
350
+ } as const )
351
+ ) ,
304
352
305
353
// unhandled promise from async query function wrapper is invalid
306
- ...ALL_ASYNC_COMBINATIONS_TO_TEST . map ( ( query ) => ( {
307
- code : `
354
+ ...ALL_ASYNC_COMBINATIONS_TO_TEST . map (
355
+ ( query ) =>
356
+ ( {
357
+ code : `
308
358
function queryWrapper() {
309
359
doSomethingElse();
310
-
360
+
311
361
return screen.${ query } ('foo')
312
362
}
313
-
363
+
314
364
test("An invalid example test", () => {
315
365
const element = queryWrapper()
316
366
})
317
-
367
+
318
368
test("An valid example test", async () => {
319
369
const element = await queryWrapper()
320
370
})
321
371
` ,
322
- errors : [ { messageId : 'asyncQueryWrapper' , line : 9 , column : 27 } ] ,
323
- } ) ) ,
372
+ errors : [ { messageId : 'asyncQueryWrapper' , line : 9 , column : 27 } ] ,
373
+ } as const )
374
+ ) ,
324
375
// unhandled promise from async query arrow function wrapper is invalid
325
- ...ALL_ASYNC_COMBINATIONS_TO_TEST . map ( ( query ) => ( {
326
- code : `
376
+ ...ALL_ASYNC_COMBINATIONS_TO_TEST . map (
377
+ ( query ) =>
378
+ ( {
379
+ code : `
327
380
const queryWrapper = () => {
328
381
doSomethingElse();
329
382
@@ -338,11 +391,14 @@ ruleTester.run(RULE_NAME, rule, {
338
391
const element = await queryWrapper()
339
392
})
340
393
` ,
341
- errors : [ { messageId : 'asyncQueryWrapper' , line : 9 , column : 27 } ] ,
342
- } ) ) ,
394
+ errors : [ { messageId : 'asyncQueryWrapper' , line : 9 , column : 27 } ] ,
395
+ } as const )
396
+ ) ,
343
397
// unhandled promise implicitly returned from async query arrow function wrapper is invalid
344
- ...ALL_ASYNC_COMBINATIONS_TO_TEST . map ( ( query ) => ( {
345
- code : `
398
+ ...ALL_ASYNC_COMBINATIONS_TO_TEST . map (
399
+ ( query ) =>
400
+ ( {
401
+ code : `
346
402
const queryWrapper = () => screen.${ query } ('foo')
347
403
348
404
test("An invalid example test", () => {
@@ -353,7 +409,8 @@ ruleTester.run(RULE_NAME, rule, {
353
409
const element = await queryWrapper()
354
410
})
355
411
` ,
356
- errors : [ { messageId : 'asyncQueryWrapper' , line : 5 , column : 27 } ] ,
357
- } ) ) ,
412
+ errors : [ { messageId : 'asyncQueryWrapper' , line : 5 , column : 27 } ] ,
413
+ } as const )
414
+ ) ,
358
415
] ,
359
416
} ) ;
0 commit comments