How to excludes files from Angular Unit test code coverage

To Excludes files from your angular unit test code coverage you need to add this configuration angular.json file of your project.

To remove mock files or a list of files or patterns from ng test --code-coverage

"codeCoverageExclude": ["/**/*mock*.ts", "app/bar/**/*.ts"]

you can add this in test property of angular.json file as below.

"test": {
  "options": {
    "codeCoverageExclude": ["/**/*mock*.ts", "app/bar/**/*.ts"]
  }
}
 
Image

For example to remove mock files you can add this "/**/*mock*.ts" in codeCoverageExclude array and it will remove from testing this file and code coverage. A list of files or patterns can be excluded from code coverage via the codeCoverageExclude property.