Skip to content
New issue

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

Feature Request: Coverage for template files #25563

Open
ice-blaze opened this issue Jul 20, 2023 · 2 comments
Open

Feature Request: Coverage for template files #25563

ice-blaze opened this issue Jul 20, 2023 · 2 comments
Labels
area: @angular-devkit/build-angular feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature
Milestone

Comments

@ice-blaze
Copy link

ice-blaze commented Jul 20, 2023

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.

@jessicajaniuk jessicajaniuk added the feature Issue that requests a new feature label Jul 20, 2023
@ngbot ngbot bot modified the milestone: Backlog Jul 20, 2023
@jessicajaniuk jessicajaniuk changed the title Coverage for template files Feature Request: Coverage for template files Jul 20, 2023
@pkozlowski-opensource pkozlowski-opensource transferred this issue from angular/angular Jul 20, 2023
@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Jul 28, 2023
@angular-robot
Copy link
Contributor

angular-robot bot commented Jul 28, 2023

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 angular-robot bot added feature: under consideration Feature request for which voting has completed and the request is now under consideration and removed feature: votes required Feature request which is currently still in the voting phase labels Aug 7, 2023
@yjaaidi
Copy link

yjaaidi commented Dec 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: @angular-devkit/build-angular feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

4 participants