Repository navigation
Description
Command
test
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
When running unit tests for an Angular library, zone.js is not automatically imported, unlike when running tests for an Angular application.
This issue occurs when the Angular workspace is explicitly created with zoneless: false.
From what I could determine, the Angular CLI resolves the required polyfills from the polyfills property in angular.json. Since libraries do not have a polyfills configuration, zone.js is never loaded automatically.
As a result, tests that rely on Angular's testing utilities fail unless zone.js is imported manually.
Minimal Reproduction
- Create a new Angular workspace with
zoneless: false. - Generate a library.
- Add a unit test that uses Angular's testing utilities (e.g.
TestBed). - Run the library tests.
- Observe that
zone.jsis not loaded unless it is imported manually.
Workaround
To make library tests work correctly, it is necessary to manually configure the test setup by:
- Importing
zone.jsin the test setup file - Importing and providing
provideZoneChangeDetectionin the test module configuration
Your Environment
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI : 22.0.4
Angular : 22.0.2
Node.js : 24.16.0
Package Manager : npm 11.13.0
Operating System : linux x64
┌───────────────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────────────┼───────────────────┼───────────────────┤
│ @angular/animations │ 22.0.2 │ ^22.0.2 │
│ @angular/build │ 22.0.4 │ ^22.0.4 │
│ @angular/cli │ 22.0.4 │ ^22.0.4 │
│ @angular/common │ 22.0.2 │ ^22.0.2 │
│ @angular/compiler │ 22.0.2 │ ^22.0.2 │
│ @angular/compiler-cli │ 22.0.2 │ ^22.0.2 │
│ @angular/core │ 22.0.2 │ ^22.0.2 │
│ @angular/forms │ 22.0.2 │ ^22.0.2 │
│ @angular/localize │ 22.0.2 │ ^22.0.2 │
│ @angular/platform-browser │ 22.0.2 │ ^22.0.2 │
│ @angular/platform-browser-dynamic │ 22.0.2 │ ^22.0.2 │
│ @angular/router │ 22.0.2 │ ^22.0.2 │
│ @angular/service-worker │ 22.0.2 │ ^22.0.2 │
│ ng-packagr │ 22.0.0 │ ^22.0.0 │
│ rxjs │ 7.8.2 │ ~7.8.2 │
│ typescript │ 6.0.3 │ ^6.0.3 │
│ vitest │ 4.1.9 │ ^4.1.9 │
│ zone.js │ 0.16.2 │ ~0.16.2 │
└───────────────────────────────────┴───────────────────┴───────────────────┘
Anything else relevant?
To the best of my knowledge, there is currently no clear indication in the official Angular documentation addressing this specific behaviour or limitation.
Activity
fix(@angular/build): load zone.js dynamically for library unit tests
fix(@angular/build): load zone.js dynamically for library unit tests
fix(@angular/build): load zone.js dynamically for library unit tests
fix(@angular/build): load zone.js dynamically for library unit tests
angular-automatic-lock-bot commentedon Jul 30, 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.