Skip to content

fix(@schematics/angular): add a TODO for spy strategies configured with withArgs in refactor-jasmine-vitest - #34620

Open
MeAkib wants to merge 2 commits into
angular:mainfrom
MeAkib:fix/jasmine-vitest-spy-with-args
Open

MeAkib wants to merge 2 commits into
angular:mainfrom
MeAkib:fix/jasmine-vitest-spy-with-args

Conversation

@MeAkib

@MeAkib MeAkib commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Spy strategies configured for specific arguments, such as spyOn(service, 'calc').withArgs(1).and.returnValue(2), were converted to vi.spyOn(service, 'calc').mockReturnValue(undefined).withArgs(1).mockReturnValue(2) without a TODO comment. Vitest mocks have no withArgs method, so the migrated test failed with a TypeError.

Add a TODO comment for these strategies instead, since they need to be migrated manually, for example with mockImplementation().

…th withArgs in refactor-jasmine-vitest

Spy strategies configured for specific arguments, such as
`spyOn(service, 'calc').withArgs(1).and.returnValue(2)`, were converted to
`vi.spyOn(service, 'calc').mockReturnValue(undefined).withArgs(1).mockReturnValue(2)`
without a TODO comment. Vitest mocks have no `withArgs` method, so the migrated test
failed with a TypeError.

Add a TODO comment for these strategies instead, since they need to be migrated
manually, for example with `mockImplementation()`.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for handling Jasmine's .withArgs() spy strategy during the Jasmine-to-Vitest migration. Since Vitest does not have a direct equivalent, the transformer now identifies .withArgs() calls and inserts a TODO comment suggesting manual migration (e.g., using mockImplementation()). Corresponding unit tests and TODO note definitions have also been added. The feedback suggests using unwrapExpression(spyCall) to ensure that any transparent wrappers, such as parentheses or non-null assertions, are stripped before performing AST checks, preventing the withArgs check from being bypassed.

…ured with withArgs in refactor-jasmine-vitest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant