File tree Expand file tree Collapse file tree 1 file changed +29
-8
lines changed Expand file tree Collapse file tree 1 file changed +29
-8
lines changed Original file line number Diff line number Diff line change 5
5
// ------------------------------------------------------------------------------
6
6
7
7
const rule = require ( '../../../lib/rules/no-await-sync-query' ) ;
8
+ const {
9
+ SYNC_QUERIES_COMBINATIONS ,
10
+ ASYNC_QUERIES_COMBINATIONS ,
11
+ } = require ( '../../../lib/utils' ) ;
8
12
const RuleTester = require ( 'eslint' ) . RuleTester ;
9
13
10
14
// ------------------------------------------------------------------------------
@@ -14,25 +18,42 @@ const RuleTester = require('eslint').RuleTester;
14
18
const ruleTester = new RuleTester ( { parserOptions : { ecmaVersion : 2018 } } ) ;
15
19
ruleTester . run ( 'no-await-sync-query' , rule , {
16
20
valid : [
17
- {
21
+ // sync queries without await are valid
22
+ ...SYNC_QUERIES_COMBINATIONS . map ( query => ( {
23
+ code : `() => {
24
+ ${ query } ('foo')
25
+ }
26
+ ` ,
27
+ } ) ) ,
28
+
29
+ // async queries with await operator are valid
30
+ ...ASYNC_QUERIES_COMBINATIONS . map ( query => ( {
18
31
code : `async () => {
19
- getByText ('foo')
32
+ await ${ query } ('foo')
20
33
}
21
34
` ,
22
- } ,
35
+ } ) ) ,
36
+
37
+ // async queries with then method are valid
38
+ ...ASYNC_QUERIES_COMBINATIONS . map ( query => ( {
39
+ code : `() => {
40
+ ${ query } ('foo').then(() => {});
41
+ }
42
+ ` ,
43
+ } ) ) ,
23
44
] ,
24
45
25
- invalid : [
26
- {
46
+ invalid :
47
+ // sync queries with await operator are not valid
48
+ SYNC_QUERIES_COMBINATIONS . map ( query => ( {
27
49
code : `async () => {
28
- await getByText ('foo')
50
+ await ${ query } ('foo')
29
51
}
30
52
` ,
31
53
errors : [
32
54
{
33
55
messageId : 'noAwaitSyncQuery' ,
34
56
} ,
35
57
] ,
36
- } ,
37
- ] ,
58
+ } ) ) ,
38
59
} ) ;
You can’t perform that action at this time.
0 commit comments