Fix element is not imported jest/describe/it/expect in Webstorm

Unresolved function or method

If you are writting tests with Jest in Webstorm and are annoyed with underline functions with message Unresolved function or method, there is one nice solution I couldn’t find easy.

npm install -g @types/jest 
It will be saved in global node modules directory on location: /usr/local/lib.

Now it needs to be added in Webstorm:

Webstorm -> Preferences -> Languages & Frameworks -> JavaScript -> Libraries

Name: jest 
Visibility: Project 
Attach files: Cmd+Shift+G and type /usr/local/lib/node_modules. Open @types, jest and choose index.d.ts.

You will have something like this:

New Library — jest

After Apply and OK first screenshot is going to be like this:

Not unresolved anymore :)

Bonus: Autocomplete works too :)


Note: If you prefer, you can add @types/jest locally with or without option --save-dev (In that case you will add index.d.ts from different location). If you don’t use save-dev, you need to repeat procedure after every update to project’s node modules.