Angular 21 new unit test builder with Karma and zone.js

Ouverte
#32,905 3 commentaires 4 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
45/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Calme
Stack technique
angular, typescript

Piste de recherche

Commencez par packages/angular/build/src/builders/unit-test/runners/karma/executor.ts et comparez la configuration du builder de tests unitaires d’Angular 20 et 21 dans angular.json. Lisez la documentation sur la migration des tests liée dans le rapport et suivez la manière dont Karma gère la configuration globale des tests. C’est terminé lorsque la configuration Karma attendue est établie et que la documentation ou le comportement de migration couvre le chemin de mise à niveau signalé.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

area: @angular/cli gemini-triaged
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

Description

After upgrading from Angular 20 to 21, I ran into NGXXXX errors when running unit tests still with Karma and zone.js.
I found a closed issue and a supposed fix for it, but that did not resolve the issue.
Others experienced the same and implemented workarounds which actually do work: StackOverflow, Reddit.

I found that the solution could be that the angular.json has to be modified to be in line with the new project template like this:

  • change "builder": "@angular/build:karma" to "builder": "@angular/build:unit-test"
  • add "runner": "karma"
  • remove the rest of the properties (according to documentation these derive from the development configuration)

I did not find anything regarding the necessity of this change in the documentation, but if that is the case, it would be wise to mention it and maybe even add a migration schematic.

Also its not clear what is the alternative for "main": "src/test.ts" which contains global test setup. My guess is that the "setupFiles" property would be the successor (like "karmaConfig" became "runnerConfig"), but that is disabled for Karma.

So my question is: Where should I put global test setup with the new "unit-test" builder when using Karma?

Thanks in advance.

Minimal Reproduction

npm test

Exception or Error

Your Environment
Angular CLI       : 21.2.5
Node.js           : 24.14.0
Package Manager   : npm 11.9.0
Operating System  : win32 x64
Anything else relevant?

No response

Langage dominant
TypeScript
Étoiles
27k
Forks
11.8k
Merge moyen
16 h 35 min
PR mergées (30 j)
176

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de angular/angular-cli

Toutes les issues de angular/angular-cli

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.