We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test
No response
When using TestBed.overrideComponent to stub a child component, the test code coverage is no longer accurate
TestBed.overrideComponent
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:
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:
Coverage is now inaccurate:
Statements : 58.33% ( 7/12 ) Branches : 90.9% ( 10/11 ) Functions : 66.66% ( 2/3 ) Lines : 66.66% ( 4/6 )
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
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Command
test
Is this a regression?
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 accurateMinimal Reproduction
Generate a new app with latest CLI and add a component:
Use app-user in app.html:
Edit angular.json to add "aot": true in the test section and run:
Coverage is 100%
Now, in the app.spec.ts, add in
beforeEach
:(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:
Coverage is now inaccurate:
Exception or Error
Your Environment
Anything else relevant?
No response
The text was updated successfully, but these errors were encountered: