Skip to content

Commit 08c66cb

Browse files
committed
fixup! fix(@schematics/angular): add a TODO for spy strategies configured with withArgs in refactor-jasmine-vitest
1 parent aea9899 commit 08c66cb

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,11 @@ function transformSpyStrategy(node: ts.CallExpression, refactorCtx: RefactorCont
182182

183183
if (spyCall) {
184184
// Vitest mocks have no `withArgs`, so a strategy for specific arguments cannot be converted.
185+
const unwrappedSpyCall = unwrapExpression(spyCall);
185186
if (
186-
ts.isCallExpression(spyCall) &&
187-
ts.isPropertyAccessExpression(spyCall.expression) &&
188-
spyCall.expression.name.text === 'withArgs'
187+
ts.isCallExpression(unwrappedSpyCall) &&
188+
ts.isPropertyAccessExpression(unwrappedSpyCall.expression) &&
189+
unwrappedSpyCall.expression.name.text === 'withArgs'
189190
) {
190191
const category = 'withArgs';
191192
reporter.recordTodo(category, sourceFile, node);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ vi.spyOn(service, 'myMethod').mockReturnValue(undefined).withArgs(1).and.returnV
157157
input: `mySpy.withArgs(1).and.returnValue(2);`,
158158
expected: `// TODO: vitest-migration: Vitest does not have a direct equivalent for spy.withArgs(). Please migrate this manually, for example with mockImplementation() that checks the arguments. See: https://vitest.dev/api/mock.html#mockimplementation
159159
mySpy.withArgs(1).and.returnValue(2);`,
160+
},
161+
{
162+
description: 'should add a TODO for a wrapped .withArgs() call',
163+
input: `mySpy.withArgs(1)!.and.returnValue(2);`,
164+
expected: `// TODO: vitest-migration: Vitest does not have a direct equivalent for spy.withArgs(). Please migrate this manually, for example with mockImplementation() that checks the arguments. See: https://vitest.dev/api/mock.html#mockimplementation
165+
mySpy.withArgs(1)!.and.returnValue(2);`,
160166
},
161167
{
162168
description: 'should correctly identify chained spies with element access (bracket notation)',

0 commit comments

Comments
 (0)