angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Feature Request: Coverage for template files

Open ice-blaze opened this issue 2 years ago • 2 comments
trafficstars

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

I was wondering if it is possible to have a coverage of the templates too. Sometimes the component typescript has no logic but everything exist in the .html file. It would be nice that the coverage could see that an *ngIf has been triggered in at least one test.

Proposed solution

Test coverage should say 50% branch coverage for this kind of template

@Component({
  selector: 'ng-if-simple',
  template: `
    <div *ngIf="show === true">First 50% code coverage</div>
    <br>
    <div *ngIf="show === false">Last 50% code coverage</div>
`
})
export class NgIfSimple {
  show = true;
}

Alternatives considered

I haven't tried anything yet. I wanted to see if the community has some input to give. Or if this idea of having coverage of templates isn't feasible at all.

ice-blaze avatar Jul 20 '23 13:07 ice-blaze

This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

You can find more details about the feature request process in our documentation.

angular-robot[bot] avatar Jul 28 '23 13:07 angular-robot[bot]

It is possible to get template code coverage by enabling AOT for tests.

It is currently possible with Vitest and PRs are open for Karma & Jest.

You can read more about this here: https://marmicode.io/blog/angular-template-code-coverage-and-future-proof-testing

yjaaidi avatar Dec 09 '24 21:12 yjaaidi