Skip to content

fix(@angular/build): explicitly fail when using Vitest runtime mocking#32443

Open
clydin wants to merge 1 commit intoangular:mainfrom
clydin:vitest/mock-warning
Open

fix(@angular/build): explicitly fail when using Vitest runtime mocking#32443
clydin wants to merge 1 commit intoangular:mainfrom
clydin:vitest/mock-warning

Conversation

@clydin
Copy link
Member

@clydin clydin commented Feb 5, 2026

The Angular unit-test builder pre-bundles tests, which prevents Vitest's runtime mocking features (like vi.mock) from working correctly as they rely on module graph manipulation that occurs before bundling. To prevent confusion and silent failures, a patch is now injected that causes vi.mock and related methods to throw a descriptive error explaining the limitation and suggesting the use of Angular TestBed for mocking instead.

Closes #31609

@clydin clydin added the target: minor This PR is targeted for the next minor release label Feb 5, 2026
The Angular unit-test builder pre-bundles tests, which prevents Vitest's runtime mocking features (like `vi.mock`) from working correctly as they rely on module graph manipulation that occurs before bundling. To prevent confusion and silent failures, a patch is now injected that causes `vi.mock` and related methods to throw a descriptive error explaining the limitation and suggesting the use of Angular TestBed for mocking instead.

Fixes angular#31609
@clydin clydin force-pushed the vitest/mock-warning branch from 3508b03 to faf32af Compare February 5, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: @angular/build target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unit-test builder with vitest runner does not support vi.mock()

1 participant