I'd like to add that it may be a good idea to use the collectCoverageFrom
option. Otherwise you will get a coverage of the files with actual tests for them, excluding those files without any tests (which might not be what you want).
Of course you can and should exclude specific files where coverage is not needed, but that's a different point.
When you use this option in your configuration, you can see during test execution that coverage is also collected for untested files, e.g.:
RUNS projects/some-lib/src/lib/directives/outside-click.directive.spec.ts (7.817 s)
RUNS projects/some-lib/src/lib/components/abc-icons/abc-icons.component.spec.ts (8.644 s)
RUNS projects/some-lib/src/lib/directives/abc-badge.directive.spec.ts (8.649 s)
Running coverage on untested files...
An example jest.config.ts
would be as follows:
import type {Config} from 'jest';
const config: Config = {
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
collectCoverage: true,
collectCoverageFrom: ["./src/**"],
coverageReporters: ['html'],
coverageDirectory: './coverage'
};
export default config;