-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Description
Command
test
Description
With zone.js
removed, ng test
fails with NG0908 (“Angular requires Zone.js”), thrown during TestBed initialization in the internal init module (before user setup files run).
Describe the solution you'd like
A builder option (e.g. "zoneless": true
) configures TestBed inside the internal init module to use provideZonelessChangeDetection() so tests run without Zone.js and without per-project workarounds.
Add a builder option (or runner option) that:
- Injects
provideZonelessChangeDetection()
into the generated init module used byinit-testbed
(the one created viacreateTestBedInitVirtualFile
). - Avoids expecting/patching Zone.js in test polyfills when zoneless is true.
- Optionally emits a clear error if both
zoneless: true
and zone.js/testing are present.
Zoneless tests will make parity with app runtime much easier. A zoneless builder option would remove friction and help teams migrate off Zone.js cleanly. 👍
Describe alternatives you've considered
Use the builder’s providersFile hook so the internal init module applies zoneless before tests:
- angular.json
"test": {
"builder": "@angular/build:unit-test",
"options": {
"tsConfig": "tsconfig.spec.json",
"runner": "vitest",
"buildTarget": "::development",
"providersFile": "src/test-providers.ts"
}
}
- src/test-providers.ts
import { provideZonelessChangeDetection } from '@angular/core';
export default [provideZonelessChangeDetection()];
- tsconfig.spec.json (ensure the file is compiled):
"files": ["src/test-setup.ts", "src/test-providers.ts"]
...this works but is not discoverable and requires extra wiring that could be automated by the builder.