Skip to content

Vitest coverage branches false reports #31644

Closed as duplicate
Closed as duplicate

Description

@LeonEck

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

With 21.0.0-next.10 vitest produces several false reports for the covered branches.

Minimal Reproduction

This can already be observed when creating a new project, installing @vitest/coverage-v8 and running ng test --no-watch --coverage:

Image

Here is a larger example that showcases several instances:

protected readonly title = signal('next-ten');

protected readonly someInput = input.required<string>();

constructor() {
  if (true) {
    console.log(this.title());
  }
}
Image

I also observed (so far only in a pipe) that implemented interfaces are not reported as covered:

@Pipe({
  name: 'myTransform',
})
export class MyTransformPipe implements PipeTransform {
  transform(value: string, ...args: unknown[]): unknown {
    return value.toUpperCase();
  }
}
describe('MyTransformPipe', () => {
  it('create an instance', () => {
    const pipe = new MyTransformPipe();
    expect(pipe).toBeTruthy();
    expect(pipe.transform('test')).toBe('TEST');
  });
});
Image

Some more context:

Setting aot to false results in almost all lines getting covered. Only the if (true) case still reports that the else path was not taken.
With aot=false, karma produces 100% coverage.
But with aot=true, karma only reports these findings:

Image Image

Exception or Error


Your Environment

Angular CLI       : 21.0.0-next.10
Angular           : 21.0.0-rc.0
Node.js           : 24.11.0
Package Manager   : npm 11.6.2
Operating System  : darwin arm64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 21.0.0-next.10    │ ^21.0.0-next.10   │
│ @angular/cli              │ 21.0.0-next.10    │ ^21.0.0-next.10   │
│ @angular/common           │ 21.0.0-rc.0       │ ^21.0.0-next.0    │
│ @angular/compiler         │ 21.0.0-rc.0       │ ^21.0.0-next.0    │
│ @angular/compiler-cli     │ 21.0.0-rc.0       │ ^21.0.0-next.0    │
│ @angular/core             │ 21.0.0-rc.0       │ ^21.0.0-next.0    │
│ @angular/forms            │ 21.0.0-rc.0       │ ^21.0.0-next.0    │
│ @angular/platform-browser │ 21.0.0-rc.0       │ ^21.0.0-next.0    │
│ @angular/router           │ 21.0.0-rc.0       │ ^21.0.0-next.0    │
│ rxjs                      │ 7.8.2             │ ~7.8.0            │
│ typescript                │ 5.9.3             │ ~5.9.2            │
└───────────────────────────┴───────────────────┴───────────────────┘

Anything else relevant?

No response

Activity

  1. angular-automatic-lock-bot commented on Nov 30, 2025

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  2. locked and limited conversation to collaborators on Nov 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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