Skip to content

Testing and code coverage with JEST #446

@otroboe

Description

@otroboe

I'm submitting a...

[ ] 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

Current behavior

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.

Expected behavior

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.

Minimal reproduction of the problem with instructions

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

cats-coverage

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);
    });
  });

Environment

- Nest version: 4.6.3
- Node version: 8.9.4
- Platform: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions