I'm having a react-native app.
Today I added unit tests with Jest and I hooked up Travis CI. When I run the tests locally, everything is fine. but when they run in Travis, I get this error:
Validation Error: Preset react-native not found.
Thanks.
I'm having a react-native app.
Today I added unit tests with Jest and I hooked up Travis CI. When I run the tests locally, everything is fine. but when they run in Travis, I get this error:
Validation Error: Preset react-native not found.
Thanks.
I had this issue and even tried it in a fresh project.
I fixed it by removing
"jest": {
"preset": "react-native"
}
from my package.json.
Doing this enabled me to run npm run test or jest to run jest.
My guess (i could be wrong) is newer versions of jest wont need that config in the packages.json file anymore.
I had this issue solved by updating jest, jest-ci package.
Why we have this issue?
I compared react-native from version 0.57.0 to 0.59.3 and found that react-native replaced jest-preset.json with jest-preset.js, but jest older versions only support jest-preset.json.
So all we need to do is to upgrade jest and jest-cli to the latest version where it support both .js and .json
You can check 'node_modules/jest-config/build/normalize.js' if you can find
const PRESET_EXTENSIONS = ['.json', '.js'];
you are at the correct version.
In my case, it happened because I was working on a module (library) that only had 'react-native' as in peerDependencies. Adding 'react-native' to "devDepenencies" fixed the issue.