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

…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'`.

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

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