Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is jest looking for a test file that no longer exists?

While creating new tests, I got this error:

Determining test suites to run...Error: ENOENT: no such file or directory, stat '/home/andrew/Documents/wise-fox/The-App/src/tests/components/AlertsComponent/AlertsPages/PromoPage3.test.js'
    at Object.fs.statSync (fs.js:948:11)
    at Object.statSync (/home/andrew/Documents/wise-fox/The-App/node_modules/graceful-fs/polyfills.js:297:22)
    at fileSize (/home/andrew/Documents/wise-fox/The-App/node_modules/jest/node_modules/jest-cli/build/test_sequencer.js:71:73)
    at tests.sort (/home/andrew/Documents/wise-fox/The-App/node_modules/jest/node_modules/jest-cli/build/test_sequencer.js:91:34)
    at Array.sort (native)
    at TestSequencer.sort (/home/andrew/Documents/wise-fox/The-App/node_modules/jest/node_modules/jest-cli/build/test_sequencer.js:77:18)
    at /home/andrew/Documents/wise-fox/The-App/node_modules/jest/node_modules/jest-cli/build/run_jest.js:148:26
    at Generator.next (<anonymous>)
    at step (/home/andrew/Documents/wise-fox/The-App/node_modules/jest/node_modules/jest-cli/build/run_jest.js:27:377)
    at /home/andrew/Documents/wise-fox/The-App/node_modules/jest/node_modules/jest-cli/build/run_jest.js:27:537

The error is trying to look for a test file that no longer exists. I had copied a number of tests and then adapted the names of the files as well as the tests inside to fit the new files.

Previously, jest just realized that certain test files had disappeared (because of renaming), but in this case jest thinks these files still exist. I'm not sure why, and I'm not sure how to fix it.

Framework: React 16 OS: Linux Elementary OS

like image 338
Andrew Horn Avatar asked Mar 21 '18 05:03

Andrew Horn


People also ask

Which of the files would Jest pick up as a test file?

Creating Test Files Jest will treat any file that ends in . test. js or . spec.

What are the limitations of Jest?

Limitations of Jest TestingIt has less tooling and library support available compared to more mature libraries (like Mocha). This can be a big drawback for developers who want to run and debug their tests in an IDE like WebStorm. Using auto-mocking features can slow down your test suite.


2 Answers

For me it was not a snapshot issue, but a cache issue. Run

jest --clearCache

to get rid of it.

like image 93
tn4foxxah Avatar answered Sep 22 '22 11:09

tn4foxxah


Ah, it had something to do with the obsolete snapshot files. I deleted them manually and the tests ran just fine

like image 40
Andrew Horn Avatar answered Sep 20 '22 11:09

Andrew Horn