Skip to content

fix(@schematics/angular): add the missing vi import for toHaveBeenCalledBefore in refactor-jasmine-vitest - #34670

Open
MeAkib wants to merge 1 commit into
angular:mainfrom
MeAkib:fix/jasmine-vitest-called-before-vi-import
Open

MeAkib wants to merge 1 commit into
angular:mainfrom
MeAkib:fix/jasmine-vitest-called-before-vi-import

Conversation

@MeAkib

@MeAkib MeAkib commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

The toHaveBeenCalledBefore transformation rewrites the matcher to a comparison of vi.mocked(spy).mock.invocationCallOrder values but never registers vi as a pending value import. When the schematic runs with --add-imports, the migrated file only imports expect and fails to compile with "Cannot find name 'vi'" unless another transformation in the same file happens to use vi.

Register the vi import when the matcher is transformed, as every other transformation that emits vi.* already does.

The new spec fails without the fix: the migrated output contained import { expect } from 'vitest' instead of import { expect, vi } from 'vitest'.

@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 updates the Jasmine-to-Vitest refactoring transformer to ensure that the 'vi' import is correctly added when transforming 'toHaveBeenCalledBefore' matchers. Specifically, it passes 'pendingVitestValueImports' to 'transformToHaveBeenCalledBefore' and calls 'addVitestValueImport' to register the 'vi' import. A corresponding unit test has also been added to verify this behavior. There are no review comments, so I have no additional feedback to provide.

@alan-agius4 alan-agius4 added the target: patch This PR is targeted for the next patch release label Nov 9, 2026
@alan-agius4 alan-agius4 added the action: merge The PR is ready for merge by the caretaker label Nov 9, 2026
…ledBefore in refactor-jasmine-vitest

The `toHaveBeenCalledBefore` transformation rewrites the matcher to a comparison of
`vi.mocked(spy).mock.invocationCallOrder` values but never registers `vi` as a pending
value import. When the schematic runs with `--add-imports`, the migrated file only
imports `expect` and fails to compile with "Cannot find name 'vi'" unless another
transformation in the same file happens to use `vi`.

Register the `vi` import when the matcher is transformed, as every other transformation
that emits `vi.*` already does.

The new spec fails without the fix: the migrated output contained
`import { expect } from 'vitest'` instead of `import { expect, vi } from 'vitest'`.
@alan-agius4
alan-agius4 force-pushed the fix/jasmine-vitest-called-before-vi-import branch from 87098a2 to 3186ef4 Compare November 9, 2026 14:23
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