Jest requires `--no-cache` for proper coverage
See original GitHub issueI have been digging into why many of our well tested components/views are not showing up on coverage reports, and I noticed that if I applied the --no-cache flag to jest I started getting appropriate coverage numbers. There seems to be an issue with the vue-jest caching mechanism that may be preventing some from getting appropriate coverage numbers.
We copied our settings from https://github.com/eddyerburgh/vue-test-utils-jest-example
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:28 (13 by maintainers)
Top Results From Across the Web
Jest CLI Options
The jest command line runner has a number of useful options. You can run jest --help to view all available options. Many of...
Read more >How can I clear the Jest cache? - Stack Overflow
As of Jest 22.0.0+, you can use the --clearCache option: Deletes the Jest cache directory and then exits without running tests.
Read more >Jest CLI Options - Robin Pokorny
Whether to use the cache. Defaults to true. Disable the cache using --no-cache . Note: the cache should only be disabled if you...
Read more >Using Visual Studio Code to debug Jest based unit tests
The need. Jest has become the de facto standard for building unit tests. ... no-cache: Disable the cache, Jest caches transformed module files...
Read more >vscode-jest-runner - Visual Studio Marketplace
vscode-jest-runner is focused on running or debugging a specific test ... JST/TSX with CRA you need to have a valid babel and jest...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This issue came out of nowhere for me, took me way too long to recognize that it’s a cache error.
FIX
All tests work again with adding
--no-cacheto the test script:"test:unit": "vue-cli-service test:unit --no-cache"SETUP
jest.config.jsERROR
Here is the error from console:
TEST
@eddyerburgh
Even the most simple
isVueInstancetest fails:…but again, other tests fail, too.
This one is a little frustrating for me. Using
--no-cachefixes the test, but if I’m using it in conjunction with--watchthen changes aren’t picked up as I make them, so the only way to see if I’ve broken something is to manually runjest. First world problems, but it’d be nice to have my test runner up while building so as to make the flow a bit less tedious.example.spec.tsexample.vueexample.tsSo if I have
jest --watch --no-cacherunning, and changemsginexample.tsto'Hey Vue'the change isn’t picked up andjeststill thinks it’s passing. Not sure if there’s a way around that injestor if it’s the purview ofvue-jestbut seems relevant to the conversation here.