@@ -8,15 +8,19 @@ const ruleTester = new RuleTester({
8
8
} ,
9
9
} )
10
10
11
- const message = 'Prefer await to then().'
11
+ const message = 'Prefer await to then()/catch()/finally() .'
12
12
13
13
ruleTester . run ( 'prefer-await-to-then' , rule , {
14
14
valid : [
15
15
'async function hi() { await thing() }' ,
16
16
'async function hi() { await thing().then() }' ,
17
17
'async function hi() { await thing().catch() }' ,
18
18
'a = async () => (await something())' ,
19
+ `a = async () => {
20
+ try { await something() } catch (error) { somethingElse() }
21
+ }` ,
19
22
'something().then(async () => await somethingElse())' ,
23
+ 'function foo() { hey.somethingElse(x => {}) }' ,
20
24
] ,
21
25
22
26
invalid : [
@@ -30,12 +34,20 @@ ruleTester.run('prefer-await-to-then', rule, {
30
34
} ,
31
35
{
32
36
code : 'function foo() { hey.then(function() { }).then(x).catch() }' ,
33
- errors : [ { message } , { message } ] ,
37
+ errors : [ { message } , { message } , { message } ] ,
34
38
} ,
35
39
{
36
40
code :
37
41
'async function a() { hey.then(function() { }).then(function() { }) }' ,
38
42
errors : [ { message } , { message } ] ,
39
43
} ,
44
+ {
45
+ code : 'function foo() { hey.catch(x => {}) }' ,
46
+ errors : [ { message } ] ,
47
+ } ,
48
+ {
49
+ code : 'function foo() { hey.finally(x => {}) }' ,
50
+ errors : [ { message } ] ,
51
+ } ,
40
52
] ,
41
53
} )
0 commit comments