Andrew Horn
Andrew Horn

Reputation: 2579

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

Upvotes: 11

Views: 6069

Answers (3)

tn4foxxah
tn4foxxah

Reputation: 297

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

jest --clearCache

to get rid of it.

Upvotes: 16

Divyanshu Rawat
Divyanshu Rawat

Reputation: 4721

Just, delete the generated directory snapshots it will be generated where you have written YOUR_FILE_NAME.test.js.

Upvotes: 2

Andrew Horn
Andrew Horn

Reputation: 2579

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

Upvotes: 8

Related Questions