Use absolute paths with Jest
Use absolute paths with Jest
I have create an app with create-react-app.
I have set in .env my NODE_PATH=src/
All works fine when I launch react-script start but when I launch react-script test I have an error: import is not found.
In my package.json :
"test": "jest --colors --coverage test"
Edit
It work fine with:
"jest":
"modulePaths": ["src/"],
"testURL": "http://localhost",
"jest": "^22.4.4"
2 Answers
2
You should execute your tests with
npm test
npm test
instead of directly using react-scripts
here. Jest is automatically configured while using project created by create-react-app
.
react-scripts
create-react-app
If you want to directly call jest
instead using the bundling set in react-scripts
, you have to call:
jest
react-scripts
"test": "./node_modules/jest/bin/jest.js --colors --coverage test"
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.