Skip to content

Vitest: Code coverage of html file incorrect when using overridecomponent #32502

@paulstelzer

Description

@paulstelzer

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

Code coverage with vitest in html drops to 0 percent when using overridecomponent. This is a valid test pattern to only unit test this component (https://angular.dev/guide/testing/components-scenarios#nested-component-tests).

The code coverage should still be 100%.

Minimal Reproduction

ng new <project-name> (with vitest unit test)

Update angular.json to include code coverage


        "test": {
          "builder": "@angular/build:unit-test",
          "options": {
            "coverage": true
          }
        }

ng test

Code coverage of the app.html is 100%:

File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 100 91.66 100 100
app.html 100 100 100 100
app.ts 100 91.66 100 100 11
---------- --------- ---------- --------- --------- -------------------

If you now update the app.spec.ts to:


  beforeEach(async () => {
    await TestBed.configureTestingModule({
      imports: [App],
    }).overrideComponent(App, {
      set: {
        imports: [],
        schemas: [NO_ERRORS_SCHEMA]
      }
    }).compileComponents();
  });

app.html statements coverage drops to 0 percent.

File % Stmts % Branch % Funcs % Lines Uncovered Line #s
All files 9.09 58.33 14.28 4.54
app.html 0 100 0 0 185-342
app.ts 83.33 58.33 100 100 10-11
---------- --------- ---------- --------- --------- -------------------

Exception or Error


Your Environment

Angular CLI       : 21.1.4
Angular           : 21.1.4
Node.js           : 24.5.0
Package Manager   : npm 11.5.1
Operating System  : darwin arm64

Anything else relevant?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions