Repository navigation
fix(@schematics/angular): do not drop callThrough() on existing spies in refactor-jasmine-vitest - #34555
Merged
Conversation
… in refactor-jasmine-vitest bare `spyOn` is migrated as stub now, so `spy.and.callThrough()` on spy created earlier is what turns real method back on, yet it was still dropped as redundant and left just `spy;` with no TODO vitest has no exact equivalent (`mockReset()` brings original implemntation back but also clears recorded calls), so call is now kept with TODO, chained `spyOn(...).and.callThrough()` is still removed like before
There was a problem hiding this comment.
Code Review
This pull request introduces handling for .and.callThrough() on existing spies during the Jasmine-to-Vitest migration, adding a TODO comment instead of dropping it. It also includes corresponding unit tests and TODO notes. The review feedback highlights that the current check !ts.isCallExpression is insufficient because custom helper calls (e.g., getSomeSpy().and.callThrough()) would be incorrectly treated as spy creations and silently dropped. It is recommended to explicitly check for spyOn or spyOnProperty calls and add a test case to cover this scenario.
…g spies in refactor-jasmine-vitest
clydin
approved these changes
Oct 28, 2026
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
PR Type
What is the current behavior?
Issue Number: N/A
refactor-jasmine-vitestdrops.and.callThrough()on spy that already exists and leaves justspy;Before #33266 that mostly worked since
vi.spyOncalls through anyway, now barespyOnbecomesvi.spyOn(...).mockReturnValue(undefined)and spy stays stub after migration, without any TODOPasses on Jasmine, after migration
ng testfails withAssertionError: expected undefined to be '1'and nothing points to dropped lineSpy that got
.and.returnValue('x')first keeps returning'x'same wayWhat is the new behavior?
When
.and.callThrough()is called on existing spy (spy,getSpy()), it is kept as is with TODO, so converted spec fails right on that line until it is migratedVitest has no exact equivalent there,
mockReset()brings original implementation back but also clears recorded calls, so TODO sugests it and says thatChain right on spy creation (
spyOn(...).and.callThrough(), same forspyOnPropertyandjasmine.createSpy) is removed like before, also when call is wrapped in parens or type assertionNew spec cases for existing spy fail on main (get
mySpy;andgetSpy();), wrappedspyOncase passes on main and guards new checkDoes this PR introduce a breaking change?
Other information
I went with TODO since rewrite is not 1:1. If you prefer, it can emit
spy.mockReset()directly with "verify" TODO, likearrayWithExactContents-checkdoesThat makes example above pass right after migration, but test that counts calls made before
callThrough()fails withexpected "get" to be called 2 times, but got 1 times