Using overrideComponent breaks code coverage when testing with aot: true
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 48/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- Active
- Stack technique
- angular, typescript
- Domaine
- build-system, testing
Piste de recherche
Reproduisez le problème dans l’application générée à l’aide de angular.json, app.spec.ts, TestBed.overrideComponent et des commandes fournies ng test --no-watch --code-coverage. Comparez la couverture avant et après l’override, puis suivez les points d’entrée des tests Angular CLI et de la couverture AOT. C’est terminé lorsque l’override ne rend plus la couverture du template du composant inexacte.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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 using TestBed.overrideComponent to stub a child component, the test code coverage is no longer accurate
Minimal Reproduction
Generate a new app with latest CLI and add a component:
npx @angular/cli@20.0.0-next.6 new aot-coverage --defaults --no-routing
cd aot-coverage
ng g c user
Use app-user in app.html:
<h1>Hello, aot-coverage</h1>
<app-user></app-user>
Edit angular.json to add "aot": true in the test section and run:
ng test --no-watch --code-coverage
Coverage is 100%
Statements : 100% ( 12/12 )
Branches : 100% ( 11/11 )
Functions : 100% ( 3/3 )
Lines : 100% ( 6/6 )
Now, in the app.spec.ts, add in beforeEach:
TestBed.overrideComponent(App, {
remove: {
imports: [User],
},
add: {
imports: [User],
}
});
(this happens with a proper stub of course but even removing the import and adding it back works to reproduce the issue)
Run the tests again:
ng test --no-watch --code-coverage
Coverage is now inaccurate because the template is not properly covered:
Statements : 58.33% ( 7/12 )
Branches : 90.9% ( 10/11 )
Functions : 66.66% ( 2/3 )
Lines : 66.66% ( 4/6 )
Exception or Error
Your Environment
Angular CLI: 20.0.0-next.6
Node: 22.14.0
Package Manager: npm 10.9.0
OS: darwin arm64
Angular: 20.0.0-next.7
... common, compiler, compiler-cli, core, forms
... platform-browser, router
Package Version
------------------------------------------------------
@angular-devkit/architect 0.2000.0-next.6
@angular-devkit/core 20.0.0-next.6
@angular-devkit/schematics 20.0.0-next.6
@angular/build 20.0.0-next.6
@angular/cli 20.0.0-next.6
@schematics/angular 20.0.0-next.6
rxjs 7.8.2
typescript 5.8.3
zone.js 0.15.0
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
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de angular/angular-cli
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-server Ouvertearea: @angular/build gemini-triaged
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
angular/angular-cli#33955 ·
-
area: @angular/cli gemini-triaged
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
angular/angular-cli#33055 · 1 commentaire · 3 réactions ·
-
unit-test: with --coverage, a setup file's hooks reach only the first spec file of each worker Ouvertearea: @angular/build gemini-triaged
Difficulté 4/5 3-5 jours Accessibilité débutants 72/100
angular/angular-cli#34137 ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34131 · 1 personne assignée ·
-
angular/build:library area: @angular/build gemini-triaged
angular/angular-cli#34130 · 1 personne assignée ·
Toutes les issues de angular/angular-cli
Issues similaires
-
S: triage
Difficulté 1/5 Moins d'une heure Accessibilité débutants 85/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
fix(errors): EHOSTUNREACH from a happy-eyeballs connect is reported as a resolver error (STAMP-80) Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100
snapshot-labs/stamp#666 ·
-
fix(api): prevent leaderboard SSE heartbeat from starting after disconnect during initial load Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
GauravKarakoti/SecureFlow#1070 · 1 commentaire ·
-
feature:Languages/Translations good first issue ready Web
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
digitalfabrik/integreat-app#4394 ·