Skip to content

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

Merged
dgp1130 merged 3 commits into
angular:mainfrom
MeAkib:fix/jasmine-vitest-spy-with-args
Nov 3, 2026
Merged

dgp1130 merged 3 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

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the PR. Please see the inline comments regarding .mockReturnValue(undefined) injection on spyOn(...).withArgs(...) and chained .withArgs(...) calls.

…ured with withArgs in refactor-jasmine-vitest
@MeAkib
MeAkib requested a review from alan-agius4 November 3, 2026 09:44
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Nov 3, 2026
@dgp1130
dgp1130 merged commit 0ae507d into angular:main Nov 3, 2026
41 checks passed
@dgp1130

dgp1130 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

This PR was merged into the repository. The changes were merged into the following branches:

@MeAkib
MeAkib deleted the fix/jasmine-vitest-spy-with-args branch November 4, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @schematics/angular target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants