Repository navigation
fix(@schematics/angular): do not drop callThrough() on existing spies in refactor-jasmine-vitest - #34555
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
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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