Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest Error: 'jest' is not recognized as an internal or external command, operable program or batch file

Tags:

I have already installed Jest in my React project. I even installed jest-cli, but still can't use Jest in the command line. I can do an npm test, as it is in my package.json, but I have problems with the test, and in order to fix it I need to access the 'jest' command. (I need to run jest --init and to create the config file.) Thank you in advance!

See Getting Started - Jest.

like image 814
Gergan Zhekov Avatar asked Dec 05 '18 18:12

Gergan Zhekov


People also ask

How do I run jest on Windows?

In order to run a specific test, you'll need to use the jest command. npm test will not work. To access jest directly on the command line, install it via npm i -g jest-cli or yarn global add jest-cli . Then simply run your specific test with jest bar.

What is the command to install jest?

You can run Jest directly from the CLI (if it's globally available in your PATH , e.g. by yarn global add jest or npm install jest --global ) with a variety of useful options.

What is npm run test?

It does call the command specified in the scripts. test property of package. json, but it also sets up certain environment variables, such as PATH so you can refer to commands that only exist within your node_modules directory, but not installed globally.


1 Answers

Try installing jest as a dev dependency.
npm install --save-dev jest

Then run it with npm test. Don't use jest command directly. It's not recommended.
If you want to use jest command use node_modules/.bin/jest.

like image 95
Janaka Chathuranga Avatar answered Sep 20 '22 16:09

Janaka Chathuranga