AlainIb
AlainIb

Reputation: 4728

Jest configuration setupFilesAfterEnv option was not found

I'm trying to make Jest work again on a project developped 1 year ago and not maintained.

I have an error with path of setupFilesAfterEnvor transform.

Upvotes: 29

Views: 43231

Answers (5)

Denys Bielishev
Denys Bielishev

Reputation: 31

It's incorrect setup in the IDE (webstorm is in my case). Go to Edit configuration and then edit working directory

1

2

Upvotes: 3

Shreyas Shivakumar
Shreyas Shivakumar

Reputation: 11

I was struggling with this issue too, after cracking my head around I discovered we can load the setup file using the command line arg itself. Run jest --setupFilesAfterEnv=<rootDir>/jest/setup.js and it will get discovered and loaded. Hope this helps.

Upvotes: 0

MatthewMartin
MatthewMartin

Reputation: 33193

I got this error when I had cded into a test folder and run ng test and I thought I was going to have to revert a lot of work. But it appears I was in the wrong folder.

So ng test isn't expected to run anywhere but root of yoru project and if you do, you get an unintelligible error message.

Upvotes: 2

Jason Landbridge
Jason Landbridge

Reputation: 1442

For those coming here, make sure you prefix the path with <rootDir>

Like this:

setupFilesAfterEnv: ['<rootDir>/node_modules/@hirez_io/observer-spy/dist/setup-auto-unsubscribe.js']

Upvotes: 8

Kornelia Frey
Kornelia Frey

Reputation: 101

You might want to delete your node modules, package-lock.json and run npm i again, I had a similar issue and that was a fix for me. Also try npm cache clean --force

Upvotes: 3

Related Questions