Title: `unit-test` builder with `vitest` runner does not support `vi.mock()` · Issue #31609 · angular/angular-cli · GitHub
Open Graph Title: `unit-test` builder with `vitest` runner does not support `vi.mock()` · Issue #31609 · angular/angular-cli
X Title: `unit-test` builder with `vitest` runner does not support `vi.mock()` · Issue #31609 · angular/angular-cli
Description: Command test Description 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 t...
Open Graph Description: Command test Description 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/...
X Description: Command test Description 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/guid...
Opengraph URL: https://github.com/angular/angular-cli/issues/31609
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`unit-test` builder with `vitest` runner does not support `vi.mock()`","articleBody":"### Command\n\ntest\n\n### Description\n\nWhen 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.\n\nThis 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.\n\nLuckily, Angular developers have the luxury of dependency injection that avoids relying on test framework for replacing things with test doubles.\nThat said, there are some use cases, specially when relying on 3rd party libraries that might require module \"mocking\".\nFor 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)\n\n### Describe the solution you'd like\n\nLet vitest resolve modules 😇\n\n### Describe alternatives you've considered\n\nIn 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.","author":{"url":"https://github.com/yjaaidi","@type":"Person","name":"yjaaidi"},"datePublished":"2025-10-27T13:05:21Z","url":"https://github.com/angular/angular-cli/issues/31609"}
| 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:fab08127-a3e4-a8e0-2473-2ccc2a9e55c7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DE9E:3A8E64:111C784:16B443E:6B01E531 |
| html-safe-nonce | b7a8ea5afeb11c1a775f5720afb90cad23f498ede774bf9dc1f09ae782995bd5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERTlFOjNBOEU2NDoxMTFDNzg0OjE2QjQ0M0U6NkIwMUU1MzEiLCJ2aXNpdG9yX2lkIjoiMTA4MDE0NjQ1MDk2MjMxMDQ1MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2e3f3e6bcd2fbdf4dec41c28ec8cc5b5398603731fef3f776afafd9412b25225 |
| hovercard-subject-tag | issue:3556695455 |
| 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/31609/issue_layout |
| twitter:image | https://opengraph.githubassets.com/62907e5b4c9c0b3f0ea01240f2937961a41e415e88b42cd2b22e3c133f1536a1/angular/angular-cli/issues/31609 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/62907e5b4c9c0b3f0ea01240f2937961a41e415e88b42cd2b22e3c133f1536a1/angular/angular-cli/issues/31609 |
| og:image:alt | Command test Description 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/... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | yjaaidi |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width