-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Closed as not planned
Closed as not planned
Copy link
Labels
area: testingIssues related to Angular testing features, such as TestBedIssues related to Angular testing features, such as TestBedgemini-triagedLabel noting that an issue has been triaged by geminiLabel noting that an issue has been triaged by gemini
Milestone
Description
Which @angular/* package(s) are the source of the bug?
Don't known / other
Is this a regression?
No
Description
We mock the dependencies of our standalone components using TestBed.overrideComponent with vitest and v8-coverage.
As soon as we do this, the HTML coverage drops. It's as if the coverage provider thinks that the component is not being used at all because it's not the "real" component anymore, but an overriden version.
In the attached example repo (minimal reproduction), coverage is 100% when not using TestBed.overrideComponent:
it('should create the app', async () => {
TestBed.configureTestingModule({
imports: [App],
});
const fixture = TestBed.createComponent(App);
await fixture.whenStable();
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
After overriding the component to mock the child:
it('should still provide all code coverage', async () => {
TestBed.configureTestingModule({
imports: [App],
}).overrideComponent(App, {
set: {
imports: [MockAppChild],
},
});
const fixture = TestBed.createComponent(App);
await fixture.whenStable();
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
Please provide a link to a minimal reproduction of the bug
https://github.com/stanrogo/repro-angular-override-component-coverage
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run ng version)
Angular CLI : 21.2.0
Angular : 21.2.0
Node.js : 20.20.0
Package Manager : npm 11.8.0
Operating System : win32 x64
┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build │ 21.2.0 │ 21.2.0 │
│ @angular/cli │ 21.2.0 │ 21.2.0 │
│ @angular/common │ 21.2.0 │ 21.2.0 │
│ @angular/compiler │ 21.2.0 │ 21.2.0 │
│ @angular/compiler-cli │ 21.2.0 │ 21.2.0 │
│ @angular/core │ 21.2.0 │ 21.2.0 │
│ @angular/platform-browser │ 21.2.0 │ 21.2.0 │
│ rxjs │ 7.8.2 │ 7.8.2 │
│ typescript │ 5.9.3 │ 5.9.3 │
│ vitest │ 4.0.18 │ 4.0.18 │
└───────────────────────────┴───────────────────┴───────────────────┘
Anything else?
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: testingIssues related to Angular testing features, such as TestBedIssues related to Angular testing features, such as TestBedgemini-triagedLabel noting that an issue has been triaged by geminiLabel noting that an issue has been triaged by gemini