Skip to content

Commit 4c69f0c

Browse files
committed
fix(@schematics/angular): add a TODO for negated expectAsync matchers in refactor-jasmine-vitest
Negated async matchers such as `expectAsync(promise).not.toBeResolved()` were left unchanged without a TODO comment, so the migrated test failed at runtime because `expectAsync` does not exist in Vitest. Negated async matchers have no exact Vitest equivalent, so add the existing unsupported `expectAsync` matcher TODO comment to them.
1 parent ef600f2 commit 4c69f0c

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-matcher.ts‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,27 @@ export function transformExpectAsync(
259259
node: ts.Node,
260260
{ sourceFile, reporter }: RefactorContext,
261261
): ts.Node {
262+
if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression)) {
263+
return node;
264+
}
265+
266+
// Negated async matchers have no exact equivalent (e.g. `.not.toBeResolvedTo()` also passes on rejection).
267+
const notPae = node.expression.expression;
262268
if (
263-
!ts.isCallExpression(node) ||
264-
!ts.isPropertyAccessExpression(node.expression) ||
265-
!ts.isCallExpression(node.expression.expression)
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'
266274
) {
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)) {
267283
return node;
268284
}
269285

‎packages/schematics/angular/refactor/jasmine-vitest/transformers/jasmine-matcher_spec.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ describe('transformExpectAsync', () => {
8484
await expectAsync(myPromise).toBeSomethingElse();
8585
`,
8686
},
87+
{
88+
description: 'should add a TODO for a negated expectAsync matcher',
89+
input: `await expectAsync(myPromise).not.toBeResolved();`,
90+
expected: `
91+
// TODO: vitest-migration: Unsupported expectAsync matcher ".not.toBeResolved()" found. Please migrate this manually.
92+
await expectAsync(myPromise).not.toBeResolved();
93+
`,
94+
},
8795
{
8896
description: 'should add a specific TODO for toBePending',
8997
input: `await expectAsync(myPromise).toBePending();`,

0 commit comments

Comments
 (0)