TS-Jest should exclude all private methods from the coverage report.
When running jest --coverage the coverage report should not complain about private methods not being tested
// type-class.ts
export class MyClass {
public method1() {
return `I'm public`;
}
private method2() {
return `I'm private`;
}
}
// myclass_spec.ts
import { MyClass } from '../type-class';
describe('MyClass', () => {
it('test public method', () => {
const x = new MyClass();
const expectation = x.method1();
expect(expectation).toEqual(`I'm public`);
})
});
$ jest --coverage
---------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
---------------|----------|----------|----------|----------|-------------------|
All files | 66.67 | 100 | 50 | 66.67 | |
type-class.ts | 66.67 | 100 | 50 | 66.67 | 7 |
---------------|----------|----------|----------|----------|-------------------|
I think.. it makes perfectly sense to track coverage on private methods?
ts-jest doesn't handle coverage at all so there's not much that can be done here
this would be a good feature though. Any plan to implement this?
@GeeWee not really, _often_ private methods are left apart
I can't think of a single good reason not to get coverage from private methods unless you're not actually testing them and trying to claim coverage numbers you don't actually have. Am I missing something?
Sorry to resurrect a long-forgotten discussion, but I was looking for a solution to the same problem and stumbled upon this thread.
Regarding testing private methods. There are several reasons why I'd not recommend testing private methods:
Not sure if this question is relevant to anyone, but there were two questions on the same matter so I decided to take a minute and try to address these concerns. Cheers 馃槉
Most helpful comment
Sorry to resurrect a long-forgotten discussion, but I was looking for a solution to the same problem and stumbled upon this thread.
Regarding testing private methods. There are several reasons why I'd not recommend testing private methods:
Not sure if this question is relevant to anyone, but there were two questions on the same matter so I decided to take a minute and try to address these concerns. Cheers 馃槉