4

I am trying to inspect a single test so I run:

npm test alerts.actionCreators.test.js

The test passes, and then I get a huge printout of code coverage and then a failure for not meeting global standards. Can I skip this part of testing while I focus on the just whether the test passes or fails?

smuggledPancakes
  • 9,881
  • 20
  • 74
  • 113

4 Answers4

8

I found a hack that mostly works: --collectCoverageOnlyFrom ''. With this the coverage table will be empty and take only about 5 lines.

JJPandari
  • 3,454
  • 1
  • 17
  • 24
  • 1
    In addition, I have just found another command from [this answer](https://stackoverflow.com/a/69443465/10102533) : --collectCoverage=false – Abdullah Bayram Jan 16 '23 at 23:57
3

I would recommend adding a second test command to your package.json :

{
  "test:watch": "jest --watch-all",
  ...
}

Jest will watch for changes in your tests/implementation and re-run the tests automatically. It should not cover the tests in watch mode.

It's good idea to run a coverage on your code from time to time. To make sure jest excluded code you don't want to cover, make sure to configure your jest config accordingly:

{
  collectCoverageFrom: ["src/**/{!(*.d.ts),}.{ts,js,.tsx,.jsx}"],
  ...
}

More information about jest configuration can be found here.

jaspenlind
  • 349
  • 2
  • 6
0

Just add path to your file in coveragePathIgnorePatterns in you Jest configuration in package.json. See the documentation

lukaleli
  • 3,427
  • 3
  • 22
  • 32
0

If you have coverage thresholds set in your jest config file, then I recommend running:

jest --watch --coverageThreshold '{}'

This will ignore/override the thresholds so that watch doesn't report failing thresholds, since it only knows about coverage for the handful of files that you've changed. This also allows you to run a much smaller number of tests for each change, compared to --watchAll.

You can also pass that in the settings of the VS Code Jest extension.

enter image description here

blwinters
  • 1,911
  • 19
  • 40