Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,27 @@ export function transformExpectAsync(
node: ts.Node,
{ sourceFile, reporter }: RefactorContext,
): ts.Node {
if (!ts.isCallExpression(node) || !ts.isPropertyAccessExpression(node.expression)) {
return node;
}

// Negated async matchers have no exact equivalent (e.g. `.not.toBeResolvedTo()` also passes on rejection).
const notPae = node.expression.expression;
if (
!ts.isCallExpression(node) ||
!ts.isPropertyAccessExpression(node.expression) ||
!ts.isCallExpression(node.expression.expression)
ts.isPropertyAccessExpression(notPae) &&
notPae.name.text === 'not' &&
ts.isCallExpression(notPae.expression) &&
ts.isIdentifier(notPae.expression.expression) &&
notPae.expression.expression.text === 'expectAsync'
) {
const category = 'unsupported-expect-async-matcher';
reporter.recordTodo(category, sourceFile, node);
addTodoComment(node, category, { name: `not.${node.expression.name.text}` });

return node;
}

if (!ts.isCallExpression(node.expression.expression)) {
return node;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ describe('transformExpectAsync', () => {
await expectAsync(myPromise).toBeSomethingElse();
`,
},
{
description: 'should add a TODO for a negated expectAsync matcher',
input: `await expectAsync(myPromise).not.toBeResolved();`,
expected: `
// TODO: vitest-migration: Unsupported expectAsync matcher ".not.toBeResolved()" found. Please migrate this manually.
await expectAsync(myPromise).not.toBeResolved();
`,
},
{
description: 'should add a specific TODO for toBePending',
input: `await expectAsync(myPromise).toBePending();`,
Expand Down
Loading