Skip to content

zone.js is not automatically loaded when running unit-test builder for Angular libraries #33477

Closed

Description

@Carlosamouco

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

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

  1. Create a new Angular workspace with zoneless: false.
  2. Generate a library.
  3. Add a unit test that uses Angular's testing utilities (e.g. TestBed).
  4. Run the library tests.
  5. 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.

Activity

  1. added
    gemini-triaged
    on Jun 26, 2026
  2. added this to the needsTriage milestone on Jun 26, 2026
  3. added 2 commits that reference this issue on Jun 27, 2026
    f28bcfb
    06359f1
  4. added 2 commits that reference this issue on Jun 29, 2026
    61e25fb
    7c0d9f0
  5. angular-automatic-lock-bot commented on Jul 30, 2026

    @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.

  6. locked and limited conversation to collaborators on Jul 30, 2026
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

    area: @angular/buildgemini-triaged

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions