Skip to content

fix(@schematics/angular): migrate spy.calls.first().args in refactor-jasmine-vitest - #34517

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
thekhegay:jasmine-vitest-first-args
Oct 26, 2026
Merged

alan-agius4 merged 1 commit into
angular:mainfrom
thekhegay:jasmine-vitest-first-args

Conversation

@thekhegay

Copy link
Copy Markdown
Contributor

PR Checklist

PR Type

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

refactor-jasmine-vitest turns spy.calls.first() into vi.mocked(spy).mock.calls[0], which is argumnets array of first call, and keeps .args that follows it
So expect(spy.calls.first().args[0]).toBe(1) becomes expect(vi.mocked(spy).mock.calls[0].args[0]).toBe(1) and converted spec does not build with ng test (checked on 22.3.0-next.3):

✘ [ERROR] TS2339: Property 'args' does not exist on type '[id: number, flag?: boolean | undefined]'. [plugin angular-compiler]

Without type check it throws Cannot read properties of undefined (reading '0')
mostRecent().args and all()[i].args (#33206) already drop .args, only first() was missed

What is the new behavior?

spy.calls.first().args becomes vi.mocked(spy).mock.calls[0], in same transformer that handles mostRecent().args
Same spec after conversion builds and passes with ng test
Two new cases in jasmine-spy_spec.ts, both fail on main

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@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 extends the Jasmine-to-Vitest migration schematic to support transforming spy.calls.first().args and its indexed accesses into the Vitest equivalent vi.mocked(spy).mock.calls[0]. It updates the AST transformer to handle .first calls similarly to .mostRecent and adds corresponding unit tests to verify the behavior. No review comments were provided, and the implementation is clean and correct.

@alan-agius4 alan-agius4 added target: patch This PR is targeted for the next patch release action: merge The PR is ready for merge by the caretaker labels Oct 26, 2026
…jasmine-vitest

`spy.calls.first()` is migrated to `vi.mocked(spy).mock.calls[0]`, which is alredy arguments array of first call, but `.args` after it was kept
so `spy.calls.first().args[0]` became `vi.mocked(spy).mock.calls[0].args[0]`, which fails with TS2339 and throws at runtime
`.args` after `first()` is now dropped same way as after `mostRecent()` and `all()[i]`
@alan-agius4
alan-agius4 force-pushed the jasmine-vitest-first-args branch from 7da9c22 to f51515b Compare October 26, 2026 12:02
@alan-agius4
alan-agius4 merged commit d3acc84 into angular:main Oct 26, 2026
6 of 7 checks passed
@alan-agius4

Copy link
Copy Markdown
Collaborator

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

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