Title: Vitest module mocking doesn't work in Angular 21 · Issue #32212 · angular/angular-cli · GitHub
Open Graph Title: Vitest module mocking doesn't work in Angular 21 · Issue #32212 · angular/angular-cli
X Title: Vitest module mocking doesn't work in Angular 21 · Issue #32212 · angular/angular-cli
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 je...
Open Graph 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 neit...
X 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 ...
Opengraph URL: https://github.com/angular/angular-cli/issues/32212
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Vitest module mocking doesn't work in Angular 21","articleBody":"### Which @angular/* package(s) are the source of the bug?\n\ncore\n\n### Is this a regression?\n\nNo\n\n### Description\n\nModule 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`.\n\n### Please provide a link to a minimal reproduction of the bug\n\nClone this and run `ng test`\nhttps://github.com/Kludgy4/ng21-broken-module-mock-repro\n\nSee broken tests here\nhttps://github.com/Kludgy4/ng21-broken-module-mock-repro/blob/main/src/app/app.spec.ts#L4-L26\n\n### Please provide the exception or error you saw\n\n```true\nTypeError: [Function downloadDocument] is not a spy or a call to a spy!\n\nor with spyOn\n\nTypeError: Cannot redefine property: downloadDocument\n```\n\n### Please provide the environment you discovered this bug in (run `ng version`)\n\n```true\nAngular CLI : 21.0.4\nAngular : 21.0.6\nNode.js : 20.19.2\nPackage Manager : npm 10.8.2\nOperating System : linux x64\n\n┌───────────────────────────┬───────────────────┬───────────────────┐\n│ Package │ Installed Version │ Requested Version │\n├───────────────────────────┼───────────────────┼───────────────────┤\n│ @angular/build │ 21.0.4 │ ^21.0.4 │\n│ @angular/cli │ 21.0.4 │ ^21.0.4 │\n│ @angular/common │ 21.0.6 │ ^21.0.0 │\n│ @angular/compiler │ 21.0.6 │ ^21.0.0 │\n│ @angular/compiler-cli │ 21.0.6 │ ^21.0.0 │\n│ @angular/core │ 21.0.6 │ ^21.0.0 │\n│ @angular/forms │ 21.0.6 │ ^21.0.0 │\n│ @angular/platform-browser │ 21.0.6 │ ^21.0.0 │\n│ @angular/router │ 21.0.6 │ ^21.0.0 │\n│ rxjs │ 7.8.2 │ ~7.8.0 │\n│ typescript │ 5.9.3 │ ~5.9.2 │\n│ vitest │ 4.0.16 │ ^4.0.8 │\n└───────────────────────────┴───────────────────┴───────────────────┘\n```\n\n### Anything else?\n\n_No response_","author":{"url":"https://github.com/Kludgy4","@type":"Person","name":"Kludgy4"},"datePublished":"2025-12-30T23:49:27Z","url":"https://github.com/angular/angular-cli/issues/32212"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:89265735-3987-4271-9f20-512fcb189624 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A8C6:380435:1AD0D:21A33:6B01E940 |
| html-safe-nonce | 2b3082bb72f68c39147701fe03aad89c3eb7c308d6de14b1c2fca0b7005d2670 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOEM2OjM4MDQzNToxQUQwRDoyMUEzMzo2QjAxRTk0MCIsInZpc2l0b3JfaWQiOiI4NTU3Nzg0MDE0ODA1NjU3OTIwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | df76388ac6bf55f4b1903435d317207fdabb823141c1e4cb151a59fdbd7f74a1 |
| hovercard-subject-tag | issue:3771681405 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/32212/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8befcda9fecc0d3564cd834b28bac0eb8e168ade4c58a441f0e60270cf0293bc/angular/angular-cli/issues/32212 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8befcda9fecc0d3564cd834b28bac0eb8e168ade4c58a441f0e60270cf0293bc/angular/angular-cli/issues/32212 |
| og:image:alt | 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 neit... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Kludgy4 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width