Skip to content

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

Closed

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

Activity

  1. added theissue type on Jun 25, 2025
  2. added a commit that references this issue on Jun 25, 2025
    bdb11f6
  3. added a commit that references this issue on Jun 25, 2025
    e0de868
  4. angular-automatic-lock-bot commented on Jul 26, 2025

    @angular-automatic-lock-bot

    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.

  5. locked and limited conversation to collaborators on Jul 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    angular/build:unit-testarea: @angular/buildfreq1: lowseverity3: brokentype: bug/fix

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions