4
4
TSESTree ,
5
5
} from '@typescript-eslint/experimental-utils' ;
6
6
import {
7
- CalledKnownMemberExpression ,
8
7
FunctionExpression ,
9
8
KnownCallExpression ,
10
9
TestCaseName ,
@@ -18,15 +17,17 @@ import {
18
17
type MessageIds = 'returnPromise' ;
19
18
type RuleContext = TSESLint . RuleContext < MessageIds , unknown [ ] > ;
20
19
21
- type ThenOrCatchCallExpression = KnownCallExpression < 'then' | 'catch' > ;
20
+ type PromiseChainCallExpression = KnownCallExpression <
21
+ 'then' | 'catch' | 'finally'
22
+ > ;
22
23
23
- const isThenOrCatchCall = (
24
+ const isPromiseChainCall = (
24
25
node : TSESTree . Node ,
25
- ) : node is ThenOrCatchCallExpression =>
26
+ ) : node is PromiseChainCallExpression =>
26
27
node . type === AST_NODE_TYPES . CallExpression &&
27
28
node . callee . type === AST_NODE_TYPES . MemberExpression &&
28
29
isSupportedAccessor ( node . callee . property ) &&
29
- [ 'then' , 'catch' ] . includes ( getAccessorValue ( node . callee . property ) ) ;
30
+ [ 'then' , 'catch' , 'finally' ] . includes ( getAccessorValue ( node . callee . property ) ) ;
30
31
31
32
const isExpectCallPresentInFunction = ( body : TSESTree . Node ) => {
32
33
if ( body . type === AST_NODE_TYPES . BlockStatement ) {
@@ -122,7 +123,7 @@ const isParentThenOrPromiseReturned = (
122
123
123
124
const verifyExpectWithReturn = (
124
125
promiseCallbacks : Array < TSESTree . CallExpressionArgument | undefined > ,
125
- node : CalledKnownMemberExpression < 'then' | 'catch' > ,
126
+ node : PromiseChainCallExpression [ 'callee' ] ,
126
127
context : RuleContext ,
127
128
testFunctionBody : TSESTree . Statement [ ] ,
128
129
) => {
@@ -167,7 +168,7 @@ export default createRule<unknown[], MessageIds>({
167
168
return {
168
169
CallExpression ( node ) {
169
170
if (
170
- ! isThenOrCatchCall ( node ) ||
171
+ ! isPromiseChainCall ( node ) ||
171
172
( node . parent && node . parent . type === AST_NODE_TYPES . AwaitExpression )
172
173
) {
173
174
return ;
0 commit comments