[ ] Regression <!--(a behavior that used to work and stopped working in a new release)-->
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
I have weird coverage reports when I'm using Jest. So I took the 01-cats-app to check if it was not from my own project, but I see the same bugs.
I see some else path not taken on import ... lines, some methods are not tested but are "covered" anyway...
I should have the proper coverage, based on what I'm testing.
I took the 01-cats-app here https://github.com/nestjs/nest/tree/master/examples/01-cats-app
npm install
npm run test:coverage
Opening the html report of the controller from
./coverage/lcov-report/src/cats/cats.controller.ts.html

The only test is:
describe('findAll', () => {
it('should return an array of cats', async () => {
const result = ['test'];
jest.spyOn(catsService, 'findAll').mockImplementation(() => result);
expect(await catsController.findAll()).toBe(result);
});
});
- Nest version: 4.6.3
- Node version: 8.9.4
- Platform: Linux
I found a (the ?) fix for my issue. I have to add "mapCoverage": true in the jest.json config file.
More infos here:
https://github.com/kulshekhar/ts-jest#coverage
https://medium.com/@mtiller/debugging-with-typescript-jest-ts-jest-and-visual-studio-code-ef9ca8644132
I'm waiting for another opinion, to close this issue, because if it's the right fix, maybe we should to a PR on the cats example.
Hi @otroboe
This was a problem with Jest and Typescript, I found this solution when i faced this problem later.
and yes, this this definitely the correct solution.
It always about wrong code maps :smile:
anyway, you are free to make a PR to all other examples.
another TIP: these kind of issues should be on stackoverflow not here
Thanks.
FYI, since Jest 22.4.0, the option mapCoverage is deprecated !
https://github.com/facebook/jest/blob/master/CHANGELOG.md#2240
https://github.com/facebook/jest/pull/5177
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
FYI, since Jest
22.4.0, the optionmapCoverageis deprecated !https://github.com/facebook/jest/blob/master/CHANGELOG.md#2240
https://github.com/facebook/jest/pull/5177