Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature request: First-class zoneless support in @angular/build:unit-test (Vitest) #31195

@jitterbox

Description

@jitterbox

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 by init-testbed (the one created via createTestBedInitVirtualFile).
  • 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:

  1. angular.json
  "test": {
    "builder": "@angular/build:unit-test",
    "options": {
      "tsConfig": "tsconfig.spec.json",
      "runner": "vitest",
      "buildTarget": "::development",
      "providersFile": "src/test-providers.ts"
    }
  }
  1. src/test-providers.ts
  import { provideZonelessChangeDetection } from '@angular/core';
  export default [provideZonelessChangeDetection()];
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions