@@ -4,53 +4,54 @@ import { createRuleTester } from '../test-utils';
4
4
5
5
const ruleTester = createRuleTester ( ) ;
6
6
7
+ const SUPPORTED_TESTING_FRAMEWORKS = [
8
+ '@testing-library/dom' ,
9
+ '@marko/testing-library' ,
10
+ ] ;
11
+
7
12
ruleTester . run ( RULE_NAME , rule , {
8
- valid : [
13
+ valid : SUPPORTED_TESTING_FRAMEWORKS . flatMap ( ( testingFramework ) => [
9
14
...ASYNC_UTILS . map ( ( asyncUtil ) => ( {
10
15
code : `
11
- import { ${ asyncUtil } } from '@testing-library/dom ';
16
+ import { ${ asyncUtil } } from '${ testingFramework } ';
12
17
test('${ asyncUtil } util directly waited with await operator is valid', async () => {
13
18
doSomethingElse();
14
19
await ${ asyncUtil } (() => getByLabelText('email'));
15
20
});
16
21
` ,
17
22
} ) ) ,
18
-
19
23
...ASYNC_UTILS . map ( ( asyncUtil ) => ( {
20
24
code : `
21
- import { ${ asyncUtil } } from '@testing-library/dom ';
25
+ import { ${ asyncUtil } } from '${ testingFramework } ';
22
26
test('${ asyncUtil } util promise saved in var and waited with await operator is valid', async () => {
23
27
doSomethingElse();
24
28
const aPromise = ${ asyncUtil } (() => getByLabelText('email'));
25
29
await aPromise;
26
30
});
27
31
` ,
28
32
} ) ) ,
29
-
30
33
...ASYNC_UTILS . map ( ( asyncUtil ) => ( {
31
34
code : `
32
- import { ${ asyncUtil } } from '@testing-library/dom ';
35
+ import { ${ asyncUtil } } from '${ testingFramework } ';
33
36
test('${ asyncUtil } util directly chained with then is valid', () => {
34
37
doSomethingElse();
35
38
${ asyncUtil } (() => getByLabelText('email')).then(() => { console.log('done') });
36
39
});
37
40
` ,
38
41
} ) ) ,
39
-
40
42
...ASYNC_UTILS . map ( ( asyncUtil ) => ( {
41
43
code : `
42
- import { ${ asyncUtil } } from '@testing-library/dom ';
44
+ import { ${ asyncUtil } } from '${ testingFramework } ';
43
45
test('${ asyncUtil } util promise saved in var and chained with then is valid', () => {
44
46
doSomethingElse();
45
47
const aPromise = ${ asyncUtil } (() => getByLabelText('email'));
46
48
aPromise.then(() => { console.log('done') });
47
49
});
48
50
` ,
49
51
} ) ) ,
50
-
51
52
...ASYNC_UTILS . map ( ( asyncUtil ) => ( {
52
53
code : `
53
- import { ${ asyncUtil } } from '@testing-library/dom ';
54
+ import { ${ asyncUtil } } from '${ testingFramework } ';
54
55
test('${ asyncUtil } util directly returned in arrow function is valid', async () => {
55
56
const makeCustomWait = () =>
56
57
${ asyncUtil } (() =>
@@ -59,10 +60,9 @@ ruleTester.run(RULE_NAME, rule, {
59
60
});
60
61
` ,
61
62
} ) ) ,
62
-
63
63
...ASYNC_UTILS . map ( ( asyncUtil ) => ( {
64
64
code : `
65
- import { ${ asyncUtil } } from '@testing-library/dom ';
65
+ import { ${ asyncUtil } } from '${ testingFramework } ';
66
66
test('${ asyncUtil } util explicitly returned in arrow function is valid', async () => {
67
67
const makeCustomWait = () => {
68
68
return ${ asyncUtil } (() =>
@@ -72,10 +72,9 @@ ruleTester.run(RULE_NAME, rule, {
72
72
});
73
73
` ,
74
74
} ) ) ,
75
-
76
75
...ASYNC_UTILS . map ( ( asyncUtil ) => ( {
77
76
code : `
78
- import { ${ asyncUtil } } from '@testing-library/dom ';
77
+ import { ${ asyncUtil } } from '${ testingFramework } ';
79
78
test('${ asyncUtil } util returned in regular function is valid', async () => {
80
79
function makeCustomWait() {
81
80
return ${ asyncUtil } (() =>
@@ -85,10 +84,9 @@ ruleTester.run(RULE_NAME, rule, {
85
84
});
86
85
` ,
87
86
} ) ) ,
88
-
89
87
...ASYNC_UTILS . map ( ( asyncUtil ) => ( {
90
88
code : `
91
- import { ${ asyncUtil } } from '@testing-library/dom ';
89
+ import { ${ asyncUtil } } from '${ testingFramework } ';
92
90
test('${ asyncUtil } util promise saved in var and returned in function is valid', async () => {
93
91
const makeCustomWait = () => {
94
92
const aPromise = ${ asyncUtil } (() =>
@@ -132,7 +130,7 @@ ruleTester.run(RULE_NAME, rule, {
132
130
} ) ) ,
133
131
...ASYNC_UTILS . map ( ( asyncUtil ) => ( {
134
132
code : `
135
- import { ${ asyncUtil } } from '@testing-library/dom ';
133
+ import { ${ asyncUtil } } from '${ testingFramework } ';
136
134
test('${ asyncUtil } util used in with Promise.all() is valid', async () => {
137
135
await Promise.all([
138
136
${ asyncUtil } (callback1),
@@ -143,7 +141,7 @@ ruleTester.run(RULE_NAME, rule, {
143
141
} ) ) ,
144
142
...ASYNC_UTILS . map ( ( asyncUtil ) => ( {
145
143
code : `
146
- import { ${ asyncUtil } } from '@testing-library/dom ';
144
+ import { ${ asyncUtil } } from '${ testingFramework } ';
147
145
test('${ asyncUtil } util used in with Promise.all() with an await is valid', async () => {
148
146
await Promise.all([
149
147
await ${ asyncUtil } (callback1),
@@ -154,7 +152,7 @@ ruleTester.run(RULE_NAME, rule, {
154
152
} ) ) ,
155
153
...ASYNC_UTILS . map ( ( asyncUtil ) => ( {
156
154
code : `
157
- import { ${ asyncUtil } } from '@testing-library/dom ';
155
+ import { ${ asyncUtil } } from '${ testingFramework } ';
158
156
test('${ asyncUtil } util used in with Promise.all() with ".then" is valid', async () => {
159
157
Promise.all([
160
158
${ asyncUtil } (callback1),
@@ -165,7 +163,7 @@ ruleTester.run(RULE_NAME, rule, {
165
163
} ) ) ,
166
164
{
167
165
code : `
168
- import { waitFor, waitForElementToBeRemoved } from '@testing-library/dom ';
166
+ import { waitFor, waitForElementToBeRemoved } from '${ testingFramework } ';
169
167
test('combining different async methods with Promise.all does not throw an error', async () => {
170
168
await Promise.all([
171
169
waitFor(() => getByLabelText('email')),
@@ -176,7 +174,7 @@ ruleTester.run(RULE_NAME, rule, {
176
174
} ,
177
175
{
178
176
code : `
179
- import { waitForElementToBeRemoved } from '@testing-library/dom ';
177
+ import { waitForElementToBeRemoved } from '${ testingFramework } ';
180
178
test('waitForElementToBeRemoved receiving element rather than callback is valid', async () => {
181
179
doSomethingElse();
182
180
const emailInput = getByLabelText('email');
@@ -186,7 +184,7 @@ ruleTester.run(RULE_NAME, rule, {
186
184
} ,
187
185
...ASYNC_UTILS . map ( ( asyncUtil ) => ( {
188
186
code : `
189
- import { ${ asyncUtil } } from '@testing-library/dom ';
187
+ import { ${ asyncUtil } } from '${ testingFramework } ';
190
188
test('${ asyncUtil } util used in Promise.allSettled + await expression is valid', async () => {
191
189
await Promise.allSettled([
192
190
${ asyncUtil } (callback1),
@@ -197,7 +195,7 @@ ruleTester.run(RULE_NAME, rule, {
197
195
} ) ) ,
198
196
...ASYNC_UTILS . map ( ( asyncUtil ) => ( {
199
197
code : `
200
- import { ${ asyncUtil } } from '@testing-library/dom ';
198
+ import { ${ asyncUtil } } from '${ testingFramework } ';
201
199
test('${ asyncUtil } util used in Promise.allSettled + then method is valid', async () => {
202
200
Promise.allSettled([
203
201
${ asyncUtil } (callback1),
@@ -208,7 +206,7 @@ ruleTester.run(RULE_NAME, rule, {
208
206
} ) ) ,
209
207
...ASYNC_UTILS . map ( ( asyncUtil ) => ( {
210
208
code : `
211
- import { ${ asyncUtil } } from '@testing-library/dom ';
209
+ import { ${ asyncUtil } } from '${ testingFramework } ';
212
210
213
211
function waitForSomethingAsync() {
214
212
return ${ asyncUtil } (() => somethingAsync())
@@ -230,23 +228,24 @@ ruleTester.run(RULE_NAME, rule, {
230
228
})
231
229
` ,
232
230
} ,
233
-
234
- // edge case for coverage
235
- // valid async query usage without any function defined
236
- // so there is no innermost function scope found
237
- `
238
- import { waitFor } from '@testing-library/dom';
239
- test('edge case for no innermost function scope', () => {
240
- const foo = waitFor
241
- })
242
- ` ,
243
- ] ,
244
- invalid : [
231
+ {
232
+ // edge case for coverage
233
+ // valid async query usage without any function defined
234
+ // so there is no innermost function scope found
235
+ code : `
236
+ import { waitFor } from '${ testingFramework } ';
237
+ test('edge case for no innermost function scope', () => {
238
+ const foo = waitFor
239
+ })
240
+ ` ,
241
+ } ,
242
+ ] ) ,
243
+ invalid : SUPPORTED_TESTING_FRAMEWORKS . flatMap ( ( testingFramework ) => [
245
244
...ASYNC_UTILS . map (
246
245
( asyncUtil ) =>
247
246
( {
248
247
code : `
249
- import { ${ asyncUtil } } from '@testing-library/dom ';
248
+ import { ${ asyncUtil } } from '${ testingFramework } ';
250
249
test('${ asyncUtil } util not waited is invalid', () => {
251
250
doSomethingElse();
252
251
${ asyncUtil } (() => getByLabelText('email'));
@@ -266,7 +265,7 @@ ruleTester.run(RULE_NAME, rule, {
266
265
( asyncUtil ) =>
267
266
( {
268
267
code : `
269
- import { ${ asyncUtil } } from '@testing-library/dom ';
268
+ import { ${ asyncUtil } } from '${ testingFramework } ';
270
269
test('${ asyncUtil } util not waited is invalid', () => {
271
270
doSomethingElse();
272
271
const el = ${ asyncUtil } (() => getByLabelText('email'));
@@ -286,7 +285,7 @@ ruleTester.run(RULE_NAME, rule, {
286
285
( asyncUtil ) =>
287
286
( {
288
287
code : `
289
- import * as asyncUtil from '@testing-library/dom ';
288
+ import * as asyncUtil from '${ testingFramework } ';
290
289
test('asyncUtil.${ asyncUtil } util not handled is invalid', () => {
291
290
doSomethingElse();
292
291
asyncUtil.${ asyncUtil } (() => getByLabelText('email'));
@@ -306,7 +305,7 @@ ruleTester.run(RULE_NAME, rule, {
306
305
( asyncUtil ) =>
307
306
( {
308
307
code : `
309
- import { ${ asyncUtil } } from '@testing-library/dom ';
308
+ import { ${ asyncUtil } } from '${ testingFramework } ';
310
309
test('${ asyncUtil } util promise saved not handled is invalid', () => {
311
310
doSomethingElse();
312
311
const aPromise = ${ asyncUtil } (() => getByLabelText('email'));
@@ -326,7 +325,7 @@ ruleTester.run(RULE_NAME, rule, {
326
325
( asyncUtil ) =>
327
326
( {
328
327
code : `
329
- import { ${ asyncUtil } } from '@testing-library/dom ';
328
+ import { ${ asyncUtil } } from '${ testingFramework } ';
330
329
test('several ${ asyncUtil } utils not handled are invalid', () => {
331
330
const aPromise = ${ asyncUtil } (() => getByLabelText('username'));
332
331
doSomethingElse(aPromise);
@@ -353,7 +352,7 @@ ruleTester.run(RULE_NAME, rule, {
353
352
( asyncUtil ) =>
354
353
( {
355
354
code : `
356
- import { ${ asyncUtil } , render } from '@testing-library/dom ';
355
+ import { ${ asyncUtil } , render } from '${ testingFramework } ';
357
356
358
357
function waitForSomethingAsync() {
359
358
return ${ asyncUtil } (() => somethingAsync())
@@ -400,7 +399,7 @@ ruleTester.run(RULE_NAME, rule, {
400
399
( asyncUtil ) =>
401
400
( {
402
401
code : `
403
- import { ${ asyncUtil } , render } from '@testing-library/dom ';
402
+ import { ${ asyncUtil } , render } from '${ testingFramework } ';
404
403
405
404
function waitForSomethingAsync() {
406
405
return ${ asyncUtil } (() => somethingAsync())
@@ -443,5 +442,5 @@ ruleTester.run(RULE_NAME, rule, {
443
442
] ,
444
443
} as const )
445
444
) ,
446
- ] ,
445
+ ] ) ,
447
446
} ) ;
0 commit comments