Skip to content

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
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Feb 9, 2026
@clydin clydin requested a review from alan-agius4 February 9, 2026 12:41
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 9, 2026
@clydin clydin merged commit fd5cb28 into angular:main Feb 9, 2026
36 checks passed
@clydin
Copy link
Member Author

clydin commented Feb 9, 2026

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker 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()

2 participants