Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Test coverage gets wrong report when calling a method in an injected service #15479

Open
its-dibo opened this issue Jan 27, 2025 · 0 comments

Comments

@its-dibo
Copy link

Version

29.7.0

Steps to reproduce

''when testing an injected service (class) and calling its methods, non of its methods reported by jest coverage as covered

for a NestJs project

@Injectable()
export class DriverService {
 findAll(){ ... }
}

test:

beforeEach(async () => {
  let module: TestingModule = await Test.createTestingModule({
    providers: [ DriverService ],
  }).compile();

  service = module.get<DriverService>(DriverService);
});

test('defined', ()=>{
expect(service).toBeDefined(); // pass
})

test('findAll', ()=>{
    mockRepo.findBy.mockResolvedValue(null);
    mockRepo.save.mockResolvedValue(mockValue );

    let _result = await service.findAll();  // <--- findAll() is called here

    expect(mockRepo.findAll).toHaveBeenCalled;
})

running the coverage report I see that findAll (and all other methods) are not covered

Expected behavior

The method is covered

Actual behavior

The method is not covered

Additional context

No response

Environment

System:
    OS: Linux 5.15 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
    CPU: (8) x64 AMD Ryzen 7 PRO 3700U w/ Radeon Vega Mobile Gfx
  Binaries:
    Node: 22.12.0 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.9.0 - /usr/local/bin/npm
    pnpm: 9.15.4 - /usr/local/share/npm-global/bin/pnpm
  npmPackages:
    jest: 29.7.0 => 29.7.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant