Skip to content

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

Open
thekhegay wants to merge 1 commit into
angular:mainfrom
thekhegay:jasmine-vitest-first-args
Open

thekhegay wants to merge 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

…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]`

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant