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 55// ------------------------------------------------------------------------------
66
77const rule = require ( '../../../lib/rules/no-await-sync-query' ) ;
8+ const {
9+ SYNC_QUERIES_COMBINATIONS ,
10+ ASYNC_QUERIES_COMBINATIONS ,
11+ } = require ( '../../../lib/utils' ) ;
812const RuleTester = require ( 'eslint' ) . RuleTester ;
913
1014// ------------------------------------------------------------------------------
@@ -14,25 +18,42 @@ const RuleTester = require('eslint').RuleTester;
1418const ruleTester = new RuleTester ( { parserOptions : { ecmaVersion : 2018 } } ) ;
1519ruleTester . run ( 'no-await-sync-query' , rule , {
1620 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 => ( {
1831 code : `async () => {
19- getByText ('foo')
32+ await ${ query } ('foo')
2033 }
2134 ` ,
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+ } ) ) ,
2344 ] ,
2445
25- invalid : [
26- {
46+ invalid :
47+ // sync queries with await operator are not valid
48+ SYNC_QUERIES_COMBINATIONS . map ( query => ( {
2749 code : `async () => {
28- await getByText ('foo')
50+ await ${ query } ('foo')
2951 }
3052 ` ,
3153 errors : [
3254 {
3355 messageId : 'noAwaitSyncQuery' ,
3456 } ,
3557 ] ,
36- } ,
37- ] ,
58+ } ) ) ,
3859} ) ;
You can’t perform that action at this time.
0 commit comments