Command
test
Is this a regression?
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.js is 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.js in the test setup file
- Importing and providing
provideZoneChangeDetection in 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.
Command
test
Is this a regression?
The previous version in which this bug was not present was
No response
Description
When running unit tests for an Angular library,
zone.jsis 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
polyfillsproperty inangular.json. Since libraries do not have apolyfillsconfiguration,zone.jsis never loaded automatically.As a result, tests that rely on Angular's testing utilities fail unless
zone.jsis imported manually.Minimal Reproduction
zoneless: false.TestBed).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:
zone.jsin the test setup fileprovideZoneChangeDetectionin the test module configurationYour Environment
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.