Skip to content

fix(@schematics/angular): migrate CallInfo returnValue and object in refactor-jasmine-vitest - #34538

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
clydin:jasmine-vitest-call-info-props
Oct 27, 2026
Merged

alan-agius4 merged 1 commit into
angular:mainfrom
clydin:jasmine-vitest-call-info-props

Conversation

@clydin

@clydin clydin commented Oct 27, 2026

Copy link
Copy Markdown
Member

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.

…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.
@clydin
clydin marked this pull request as ready for review October 27, 2026 13:09
@clydin clydin added the target: patch This PR is targeted for the next patch release label Oct 27, 2026

@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 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.

@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Oct 27, 2026
@clydin
clydin requested a review from alan-agius4 October 27, 2026 13:16
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Oct 27, 2026
@alan-agius4
alan-agius4 merged commit 54f2618 into angular:main Oct 27, 2026
44 checks passed
@alan-agius4

Copy link
Copy Markdown
Collaborator

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

@clydin
clydin deleted the jasmine-vitest-call-info-props branch October 27, 2026 13:51
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.

2 participants