@@ -151,16 +151,24 @@ export function hasThenProperty(node: TSESTree.Node): boolean {
151
151
) ;
152
152
}
153
153
154
- export function hasChainedThen ( node : TSESTree . Node ) : boolean {
154
+ export function hasPromiseHandlerProperty ( node : TSESTree . Node ) : boolean {
155
+ return (
156
+ isMemberExpression ( node ) &&
157
+ ASTUtils . isIdentifier ( node . property ) &&
158
+ [ 'then' , 'catch' ] . includes ( node . property . name )
159
+ ) ;
160
+ }
161
+
162
+ export function hasChainedPromiseHandler ( node : TSESTree . Node ) : boolean {
155
163
const parent = node . parent ;
156
164
157
- // wait(...).then(...)
165
+ // wait(...).then(...) or wait(...).catch(...)
158
166
if ( isCallExpression ( parent ) && parent . parent ) {
159
- return hasThenProperty ( parent . parent ) ;
167
+ return hasPromiseHandlerProperty ( parent . parent ) ;
160
168
}
161
169
162
- // promise.then(...)
163
- return ! ! parent && hasThenProperty ( parent ) ;
170
+ // promise.then(...) or promise.catch(...)
171
+ return ! ! parent && hasPromiseHandlerProperty ( parent ) ;
164
172
}
165
173
166
174
export function isPromiseIdentifier (
@@ -214,7 +222,7 @@ export function isPromisesArrayResolved(node: TSESTree.Node): boolean {
214
222
* - it belongs to the `await` expression
215
223
* - it belongs to the `Promise.all` method
216
224
* - it belongs to the `Promise.allSettled` method
217
- * - it's chained with the `then` method
225
+ * - it's chained with the `then` or `catch` method
218
226
* - it's returned from a function
219
227
* - has `resolves` or `rejects` jest methods
220
228
* - has `toResolve` or `toReject` jest-extended matchers
@@ -243,7 +251,7 @@ export function isPromiseHandled(nodeIdentifier: TSESTree.Identifier): boolean {
243
251
)
244
252
return true ;
245
253
if ( hasClosestExpectHandlesPromise ( node . parent ) ) return true ;
246
- if ( hasChainedThen ( node ) ) return true ;
254
+ if ( hasChainedPromiseHandler ( node ) ) return true ;
247
255
if ( isPromisesArrayResolved ( node ) ) return true ;
248
256
} ) ;
249
257
}
0 commit comments