Skip to content

Many NG0100 errors in Karma unit tests after updating to Angular 21 #32047

@jimivdw

Description

@jimivdw

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

20.3.12

Description

When updating my app to Angular 21, all is fine, except my unit tests. There are now many, many occurrences of the NG0100: ExpressionChangedAfterItHasBeenCheckedError, which were not present before the update.

My app still heavily relies on zone.js for change detection. I also still use the older @angular-devkit/build-angular:karma builder. I am working on upgrading both, but that process is gradual and will still take significant effort.

I discovered this Reddit post where someone describes the exact same issue (in way more detail). This also includes a workaround: globally "patch" TestBed.configureTestingModule to always provideZoneChangeDetection(). As I also indicated in my comment over there, this does work, but feels too hacky and I cannot imagine this being the "official" recommended solution. Is there anything else I can do?

Minimal Reproduction

In principle:

  1. Have a zone.js-based Angular project, not using OnPush change detection (at least not everywhere)
  2. Run ng test
  3. Observe NG0100 errors

I am unfortunately unable to submit (parts of) my actual source code. Will try to see if I can make a minimal reproduction later.

Exception or Error

NG0100: ExpressionChangedAfterItHasBeenCheckedError

Your Environment

_                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI       : 21.0.1
Angular           : 21.0.2
Node.js           : 24.11.0
Package Manager   : yarn 4.12.0
Operating System  : darwin arm64

┌────────────────────────────────────┬───────────────────┬───────────────────┐
│ Package                            │ Installed Version │ Requested Version │
├────────────────────────────────────┼───────────────────┼───────────────────┤
│ @angular-devkit/architect          │ 0.2100.1          │ 0.2100.1          │
│ @angular-devkit/build-angular      │ 21.0.1            │ 21.0.1            │
│ @angular-devkit/core               │ 21.0.1            │ 21.0.1            │
│ @angular-devkit/schematics         │ 21.0.1            │ 21.0.1            │
│ @angular/animations                │ 21.0.2            │ 21.0.2            │
│ @angular/cdk                       │ 21.0.1            │ 21.0.1            │
│ @angular/cli                       │ 21.0.1            │ 21.0.1            │
│ @angular/common                    │ 21.0.2            │ 21.0.2            │
│ @angular/compiler                  │ 21.0.2            │ 21.0.2            │
│ @angular/compiler-cli              │ 21.0.2            │ 21.0.2            │
│ @angular/core                      │ 21.0.2            │ 21.0.2            │
│ @angular/forms                     │ 21.0.2            │ 21.0.2            │
│ @angular/language-service          │ 21.0.2            │ 21.0.2            │
│ @angular/material                  │ 21.0.1            │ 21.0.1            │
│ @angular/material-date-fns-adapter │ 21.0.1            │ 21.0.1            │
│ @angular/platform-browser          │ 21.0.2            │ 21.0.2            │
│ @angular/platform-browser-dynamic  │ 21.0.2            │ 21.0.2            │
│ @angular/router                    │ 21.0.2            │ 21.0.2            │
│ rxjs                               │ 7.8.2             │ 7.8.2             │
│ typescript                         │ 5.9.3             │ 5.9.3             │
│ zone.js                            │ 0.15.1            │ 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