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.
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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With