Skip to content

Commit 70f7361

Browse files
fixup! fix(@schematics/angular): preserve nested done callbacks during Vitest migration
1 parent a61b789 commit 70f7361

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ function transformPromiseBasedDone(
223223
callExpr: ts.CallExpression,
224224
doneIdentifier: ts.Identifier,
225225
): ts.Node | undefined {
226+
if (callExpr.arguments.length !== 1) {
227+
return undefined;
228+
}
229+
226230
if (
227231
ts.isPropertyAccessExpression(callExpr.expression) &&
228232
(callExpr.expression.name.text === 'then' || callExpr.expression.name.text === 'catch')

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ describe('Jasmine to Vitest Transformer - transformDoneCallback', () => {
7777
input: `it('fails', (done) => { done.fail(); });`,
7878
expected: `it('fails', async () => { throw new Error(); });`,
7979
},
80+
{
81+
description: 'should preserve a rejection handler passed alongside done in then',
82+
input: `
83+
it('loads the data', (done) => {
84+
loadData().then(done, (error) => {
85+
expect(error).toBe(expectedError);
86+
});
87+
});
88+
`,
89+
expected: `
90+
// TODO: vitest-migration: The 'done' callback was used in an unhandled way. Please migrate manually.
91+
it('loads the data', (done) => {
92+
loadData().then(done, (error) => {
93+
expect(error).toBe(expectedError);
94+
});
95+
});
96+
`,
97+
},
8098
{
8199
description: 'should handle promise rejections via catch',
82100
input: `

0 commit comments

Comments
 (0)