@@ -8,15 +8,19 @@ const ruleTester = new RuleTester({
88 } ,
99} )
1010
11- const message = 'Prefer await to then().'
11+ const message = 'Prefer await to then()/catch()/finally() .'
1212
1313ruleTester . run ( 'prefer-await-to-then' , rule , {
1414 valid : [
1515 'async function hi() { await thing() }' ,
1616 'async function hi() { await thing().then() }' ,
1717 'async function hi() { await thing().catch() }' ,
1818 'a = async () => (await something())' ,
19+ `a = async () => {
20+ try { await something() } catch (error) { somethingElse() }
21+ }` ,
1922 'something().then(async () => await somethingElse())' ,
23+ 'function foo() { hey.somethingElse(x => {}) }' ,
2024 ] ,
2125
2226 invalid : [
@@ -30,12 +34,20 @@ ruleTester.run('prefer-await-to-then', rule, {
3034 } ,
3135 {
3236 code : 'function foo() { hey.then(function() { }).then(x).catch() }' ,
33- errors : [ { message } , { message } ] ,
37+ errors : [ { message } , { message } , { message } ] ,
3438 } ,
3539 {
3640 code :
3741 'async function a() { hey.then(function() { }).then(function() { }) }' ,
3842 errors : [ { message } , { message } ] ,
3943 } ,
44+ {
45+ code : 'function foo() { hey.catch(x => {}) }' ,
46+ errors : [ { message } ] ,
47+ } ,
48+ {
49+ code : 'function foo() { hey.finally(x => {}) }' ,
50+ errors : [ { message } ] ,
51+ } ,
4052 ] ,
4153} )
0 commit comments