You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
unit-test builder with vitest runner does not support vi.mock() #31609
When using the new unit-test builder with Vitest runner, some Vitest features such as the module graph or module "mocking" with vi.mock() (https://vitest.dev/guide/mocking/modules.html) do not work.
This is due to the fact that the builder is building the tests and then providing the built chunks to Vitest so Vitest is not aware of the real module graph.
Luckily, Angular developers have the luxury of dependency injection that avoids relying on test framework for replacing things with test doubles.
That said, there are some use cases, specially when relying on 3rd party libraries that might require module "mocking".
For instance, AFAIK, the main approach to achieve Shallow testing in AOT without altering production code is to use this feature (cf. https://marmicode.io/blog/angular-template-code-coverage-and-future-proof-testing#:~:text=Shallow%20Testing%20is%20More%20Challenging)
Describe the solution you'd like
Let vitest resolve modules 😇
Describe alternatives you've considered
In the mean time, it would be nice to monkey patch vi.mock and make it throw an error indicating that the feature is not supported.
changed the title [-]`unit-test` builder does not support `vi.mock()`[/-][+]`unit-test` builder with `vitest` runner does not support `vi.mock()`[/+]on Oct 27, 2025
This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.
You can find more details about the feature request process in our documentation.
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.
We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.
You can find more details about the feature request process in our documentation.
Activity
[-]`unit-test` builder does not support `vi.mock()`[/-][+]`unit-test` builder with `vitest` runner does not support `vi.mock()`[/+]angular-robot commentedon Oct 31, 2025
This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.
You can find more details about the feature request process in our documentation.
angular-robot commentedon Dec 10, 2025
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.
Find more details about Angular's feature request process in our documentation.
angular-robot commentedon Dec 29, 2025
Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.
We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.
You can find more details about the feature request process in our documentation.
Kludgy4 commentedon Dec 31, 2025
Does an issue get reopened if it gets 20 votes after the 20 day polling process? We seems to have missed the deadline by less than 2 days
feat(@angular/build): explicitly fail when using Vitest runtime mocking
fix(@angular/build): explicitly fail when using Vitest runtime mocking
fix(@angular/build): explicitly fail when using Vitest runtime mocking
fix(@angular/build): explicitly fail when using Vitest runtime mocking
angular-automatic-lock-bot commentedon Mar 12, 2026
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.