Repository navigation
unit-test builder with vitest runner does not support vi.mock() #31609
Description
Activity
- 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 - addedfeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues
on Oct 31, 2025 - addedfeature: votes requiredFeature request which is currently still in the voting phaseFeature request which is currently still in the voting phase
on 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.
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.
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.
- addedfeature: insufficient votesLabel to add when the not a sufficient number of votes or comments from unique authorsLabel to add when the not a sufficient number of votes or comments from unique authorsand removedfeature: votes requiredFeature request which is currently still in the voting phaseFeature request which is currently still in the voting phase
on Dec 29, 2025 - marked Vitest module mocking doesn't work in Angular 21 #32212 as a duplicate of this issue
on 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
Reacted by Ramiro Jr. Franco- added a commit that references this issue
on Feb 9, 2026 angular-automatic-lock-bot commented
on Mar 12, 2026 More actionsThis 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.
- locked and limited conversation to collaborators
on Mar 12, 2026
Command
test
Description
When using the new
unit-testbuilder with Vitest runner, some Vitest features such as the module graph or module "mocking" withvi.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.mockand make it throw an error indicating that the feature is not supported.