jest icon indicating copy to clipboard operation
jest copied to clipboard

[Bug]: Missing coverage from custom test environment

Open marvasDE opened this issue 3 years ago • 1 comments

Version

29.0.3

Steps to reproduce

  1. Clone my repo at https://github.com/marvasDE/jest-sample
  2. Install packages via npm i
  3. Run npm run test:coverage

Expected behavior

100 % Stmts covered in index.js

Actual behavior

83.33 % Stmts covered in index.js

Additional context

We have a global service class, but every line which should be covered with the global service is not covered. The test is running, because there is a console.log.

Uncomment Line 12 of sample.test.ts will fix the behavior, but we would like to use a global service, because in a real project we have multiple tests, which are using a global service to reduce memory usage.

Environment

System:
    OS: Linux 5.19 Arch Linux
    CPU: (8) x64 AMD Ryzen 7 2700U with Radeon Vega Mobile Gfx
  Binaries:
    Node: 18.9.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.19.1 - /usr/bin/npm
  npmPackages:
    jest: ^29.0.3 => 29.0.3

marvasDE avatar Sep 13 '22 15:09 marvasDE

If your service is instantiated outside of a test (e.g. globalSetup or via a test environment) then that code runs outside of the context jest can pick up the coverage I think...

SimenB avatar Sep 13 '22 15:09 SimenB

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Oct 13 '22 15:10 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] avatar Nov 12 '22 16:11 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] avatar Nov 12 '22 16:11 github-actions[bot]

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

github-actions[bot] avatar Dec 13 '22 00:12 github-actions[bot]