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

Skip to content

[unit-test] karma runner doesn't support zone.js/testing auto injection #30595

Closed
@lacolaco

Description

@lacolaco

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

The experimental @angular/build:unit-test injects zone.js/testing into the polyfills of builder option but only for Vitest. In use runner: 'karma', there are no way to load zone.js/testing for the environment.

https://github.com/angular/angular-cli/blob/main/packages/angular/build/src/builders/unit-test/builder.ts#L114-L116

I think this lines should be moved to the before branching runners. (if(runnerName === 'karma'))

https://github.com/angular/angular-cli/blob/main/packages/angular/build/src/builders/unit-test/builder.ts#L61-L66

Minimal Reproduction

  • Use unit-test builder for ng test
  • Use fakeAsync in tests
  • Run ng test

Exception or Error

Error: zone-testing.js is needed for the fakeAsync() test helper but could not be found.
          Please make sure that your environment includes zone.js/testing
      at fakeAsync

Your Environment

Angular CLI: 20.0.3
Node: 22.16.0
Package Manager: pnpm 10.12.1
OS: darwin arm64

Angular: 20.0.4
... animations, common, compiler, compiler-cli, core, elements
... forms, platform-browser, platform-browser-dynamic, router

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.2000.3
@angular-devkit/core         20.0.3
@angular-devkit/schematics   20.0.3
@angular/build               20.0.3
@angular/cdk                 20.0.3
@angular/cli                 20.0.3
@schematics/angular          20.0.3
rxjs                         7.8.2
typescript                   5.8.3
zone.js                      0.15.1

Anything else relevant?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions