@@ -263,36 +263,47 @@ export function transformExpectAsync(
263263 return node ;
264264 }
265265
266- // Negated async matchers have no exact equivalent (e.g. `.not.toBeResolvedTo( )` also passes on rejection).
267- const notPae = node . expression . expression ;
266+ // When the chain continues past this call (e.g. the `withContext('msg' )` link itself),
267+ // the outermost matcher call handles the whole statement.
268268 if (
269- ts . isPropertyAccessExpression ( notPae ) &&
270- notPae . name . text === 'not' &&
271- ts . isCallExpression ( notPae . expression ) &&
272- ts . isIdentifier ( notPae . expression . expression ) &&
273- notPae . expression . expression . text === 'expectAsync'
269+ node . parent &&
270+ ts . isPropertyAccessExpression ( node . parent ) &&
271+ node . parent . expression === node
274272 ) {
275- const category = 'unsupported-expect-async-matcher' ;
276- reporter . recordTodo ( category , sourceFile , node ) ;
277- addTodoComment ( node , category , { name : `not.${ node . expression . name . text } ` } ) ;
278-
279- return node ;
280- }
281-
282- if ( ! ts . isCallExpression ( node . expression . expression ) ) {
283273 return node ;
284274 }
285275
286276 const matcherCall = node ;
287277 const matcherPae = node . expression ;
288- const expectCall = node . expression . expression ;
278+
279+ // Walk down any modifier chain (`.not`, `.already`, `.withContext(...)`) to the root call.
280+ // Modifiers have no direct vitest equivalent, so a modified matcher falls through to the
281+ // TODO handling below.
282+ const modifierNames : string [ ] = [ ] ;
283+ let expectCall : ts . CallExpression | undefined ;
284+ let current : ts . Expression = matcherPae . expression ;
285+ while ( ! expectCall ) {
286+ if ( ts . isCallExpression ( current ) ) {
287+ if ( ts . isIdentifier ( current . expression ) ) {
288+ expectCall = current ;
289+ } else {
290+ current = current . expression ;
291+ }
292+ } else if ( ts . isPropertyAccessExpression ( current ) && ts . isIdentifier ( current . name ) ) {
293+ modifierNames . unshift ( current . name . text ) ;
294+ current = current . expression ;
295+ } else {
296+ return node ;
297+ }
298+ }
289299
290300 if ( ! ts . isIdentifier ( expectCall . expression ) || expectCall . expression . text !== 'expectAsync' ) {
291301 return node ;
292302 }
293303
294304 const matcherName = ts . isIdentifier ( matcherPae . name ) ? matcherPae . name . text : undefined ;
295- const mapping = matcherName ? ASYNC_MATCHER_CHANGES . get ( matcherName ) : undefined ;
305+ const mapping =
306+ matcherName && modifierNames . length === 0 ? ASYNC_MATCHER_CHANGES . get ( matcherName ) : undefined ;
296307
297308 if ( mapping ) {
298309 reporter . reportTransformation (
@@ -314,14 +325,14 @@ export function transformExpectAsync(
314325 }
315326
316327 if ( matcherName ) {
317- if ( matcherName === 'toBePending' ) {
328+ if ( matcherName === 'toBePending' && modifierNames . length === 0 ) {
318329 const category = 'toBePending' ;
319330 reporter . recordTodo ( category , sourceFile , node ) ;
320331 addTodoComment ( node , category ) ;
321332 } else {
322333 const category = 'unsupported-expect-async-matcher' ;
323334 reporter . recordTodo ( category , sourceFile , node ) ;
324- addTodoComment ( node , category , { name : matcherName } ) ;
335+ addTodoComment ( node , category , { name : [ ... modifierNames , matcherName ] . join ( '.' ) } ) ;
325336 }
326337 }
327338
0 commit comments