Repository navigation
Closed as duplicate
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
Module mocking doesn't appear to work with vitest in ng21. I have used vi.mock and vi.spyOn and neither works. This did work however with jest (CommonJS?) and jest.mock.
Please provide a link to a minimal reproduction of the bug
Clone this and run ng test
https://github.com/Kludgy4/ng21-broken-module-mock-repro
See broken tests here
https://github.com/Kludgy4/ng21-broken-module-mock-repro/blob/main/src/app/app.spec.ts#L4-L26
Please provide the exception or error you saw
TypeError: [Function downloadDocument] is not a spy or a call to a spy!
or with spyOn
TypeError: Cannot redefine property: downloadDocument
Please provide the environment you discovered this bug in (run ng version)
Angular CLI : 21.0.4
Angular : 21.0.6
Node.js : 20.19.2
Package Manager : npm 10.8.2
Operating System : linux x64
┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build │ 21.0.4 │ ^21.0.4 │
│ @angular/cli │ 21.0.4 │ ^21.0.4 │
│ @angular/common │ 21.0.6 │ ^21.0.0 │
│ @angular/compiler │ 21.0.6 │ ^21.0.0 │
│ @angular/compiler-cli │ 21.0.6 │ ^21.0.0 │
│ @angular/core │ 21.0.6 │ ^21.0.0 │
│ @angular/forms │ 21.0.6 │ ^21.0.0 │
│ @angular/platform-browser │ 21.0.6 │ ^21.0.0 │
│ @angular/router │ 21.0.6 │ ^21.0.0 │
│ rxjs │ 7.8.2 │ ~7.8.0 │
│ typescript │ 5.9.3 │ ~5.9.2 │
│ vitest │ 4.0.16 │ ^4.0.8 │
└───────────────────────────┴───────────────────┴───────────────────┘
Anything else?
No response
Metadata
Metadata
Assignees
Labels
No labels
Activity
unit-testbuilder withvitestrunner does not supportvi.mock()#31609angular-automatic-lock-bot commentedon Jan 31, 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.