Repository navigation
fix(@schematics/angular): migrate CallInfo returnValue and object in refactor-jasmine-vitest - #34538
Merged
Merged
Conversation
…refactor-jasmine-vitest Previously, only the `.args` property of a Jasmine `CallInfo` object obtained via `spy.calls.first()`, `spy.calls.mostRecent()`, or `spy.calls.all()[i]` was migrated. Accessing `.returnValue` or `.object` on these results left the property intact on the transformed `mock.calls[i]` tuple, producing code that fails type checking and throws at runtime. These properties are now mapped to the corresponding Vitest `MockContext` members: - `spy.calls.first().returnValue` -> `vi.mocked(spy).mock.results[0].value` - `spy.calls.all()[i].returnValue` -> `vi.mocked(spy).mock.results[i].value` - `spy.calls.mostRecent().returnValue` -> `vi.mocked(spy).mock.results.at(-1)?.value` - `spy.calls.first().object` -> `vi.mocked(spy).mock.contexts[0]` - `spy.calls.all()[i].object` -> `vi.mocked(spy).mock.contexts[i]` - `spy.calls.mostRecent().object` -> `vi.mocked(spy).mock.contexts.at(-1)` The separate `transformMostRecentArgs` and `transformAllCallsArgs` handlers have been consolidated into a single `transformCallInfoProperty` transformer, and the TODO for a bare `mostRecent()` call no longer fires when one of the supported properties is accessed.
There was a problem hiding this comment.
Code Review
This pull request enhances the Jasmine-to-Vitest migration schematics by expanding the Jasmine spy transformer to support additional CallInfo properties (.returnValue and .object) and handling transparent wrappers like type assertions and parenthesized expressions. The reviewer suggests improving the accuracy of the reported transformation messages by dynamically extracting the index expression's text instead of hardcoding 'i', which can be achieved by passing the sourceFile to getCallInfoAccess.
alan-agius4
approved these changes
Oct 27, 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.
Previously, only the
.argsproperty of a JasmineCallInfoobject obtained viaspy.calls.first(),spy.calls.mostRecent(), orspy.calls.all()[i]was migrated. Accessing.returnValueor.objecton these results left the property intact on the transformedmock.calls[i]tuple, producing code that fails type checking and throws at runtime.These properties are now mapped to the corresponding Vitest
MockContextmembers:spy.calls.first().returnValue->vi.mocked(spy).mock.results[0].valuespy.calls.all()[i].returnValue->vi.mocked(spy).mock.results[i].valuespy.calls.mostRecent().returnValue->vi.mocked(spy).mock.results.at(-1)?.valuespy.calls.first().object->vi.mocked(spy).mock.contexts[0]spy.calls.all()[i].object->vi.mocked(spy).mock.contexts[i]spy.calls.mostRecent().object->vi.mocked(spy).mock.contexts.at(-1)The separate
transformMostRecentArgsandtransformAllCallsArgshandlers have been consolidated into a singletransformCallInfoPropertytransformer, and the TODO for a baremostRecent()call no longer fires when one of the supported properties is accessed.