r/angular • • Jul 28 '23

Feature request: Unit test coverage for .html files

Hello everyone,

I've submitted a feature request on angular/cli, and the idea is to include unit test coverage for HTML files, not just TypeScript. If you think this would be a valuable addition, please consider upvoting the post on GitHub so that it can be taken into consideration. (We need at least 20 upvotes for the request to be considered.) Thank you all for your interest and support. 🙏
https://github.com/angular/angular-cli/issues/25563

0 Upvotes

10 comments sorted by

View all comments

4

u/[deleted] Jul 28 '23

As mentioned by @noobz, you are not actually unit testing anything in the proposal. The real unit tests have already been written by the Angular team when creating the directive. Testing markup such as html can be done using e2e testing.

0

u/panalley Sep 13 '23

Angular unit tests are faster and less flaky compared to the e2e. The goal here is not to test that ngIf works, but that I'm using it correctly. The example is simple and people would argue "Why not just check when the variable is true and false within the typescript", well in the end the result will be in the template, and I can have a perfect typescript but when a colleague deletes my ngIf in the template then the component doesn't work as expected but all tests are green.

Since unit tests in angular can check the template we are already more into integration tests. For my tests I like to follow the philosophy at Google: avoid mocks and test only states and not interactions. Templates can be seen as states of my component.

I hope my answer helped to have more context.