'Jest: coverage is scoring 100, even for files without tests
I'm running jest --coverage against my tests, but Jest is giving me a 100 value on files that have no tests at all or test cases that don't cover all component lines/statements/functions.
Also, I expect my tests to fail if the minimum coverageThreshold is not met.
This is what I've got my jest.config.ts file:
export default {
testEnvironment: 'jsdom',
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
moduleNameMapper: {
'\\.(jpg|gif|ttf|eot|svg|png)$': '<rootDir>/test/__mocks__/fileMock.js',
'\\.(css|less|sass|scss)$': 'identity-obj-proxy',
},
testMatch: [
'<rootDir>/src/**/__tests__/**/*.(ts|tsx)',
'<rootDir>/src/**/*.{spec,test}.(ts|tsx)',
],
collectCoverageFrom: [
'<rootDir>/src/**/*.(ts|tsx)',
'!<rootDir>/node_modules/',
'!<rootDir>/src/**/*.d.ts',
],
collectCoverage: true,
coverageThreshold: {
global: {
lines: 85,
statements: 85,
functions: 85,
},
},
resetMocks: true,
moduleDirectories: ['node_modules', 'src'],
coverageDirectory: '<rootDir>/coverage',
};
You can find my implementation in this repository: https://bitbucket.org/thyagoweber/zustand-tw-training/src/coverage-issues/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

