I'm trying to install Jest
and React testing library
to my expo project(sdk 47). While installing i'm getting dependency conflict. i'm new to testing can you please help me how to install
Found: [email protected] npm ERR! node_modules/react npm ERR!
react@"18.1.0" from the root project npm ERR! peer react@">=16.0.0" from @testing-library/[email protected] npm ERR!
node_modules/@testing-library/react-native npm ERR!
@testing-library/react-native@"" from the root project npm ERR! 1 more (react-native) npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer react@"^18.2.0" from [email protected] npm ERR! node_modules/react-test-renderer npm ERR!
react-test-renderer@"^18.1.0" from the root project npm ERR! peer react-test-renderer@">=16.0.0" from @testing-library/[email protected] npm ERR!
node_modules/@testing-library/react-native npm ERR!
@testing-library/react-native@"" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See C:\Users\rikvitha\AppData\Local\npm-cache\eresolve-report.txt for a full report.npm ERR! A complete log of this run can be found in:
npm ERR!
C:\Users\rikvitha\AppData\Local\npm-cache_logs\2023-01-22T05_28_56_533Z-debug-0.log
CodePudding user response:
Are you trying to install React testing library (RTL), or React-Native testing library (RNTL)? Your question say one thing, but your error logs the other, they are two distinct libraries. I am going to assume it's RNTL, because your also using expo.
The error log says that you have several dependencies that are in conflict with each other, i.e. you have a dependency conflict. What I would recommend is to remove the dependencies and add them again (if you have a commit where everything worked, you can do git reset head --hard
to throw away your changes). I think your problem is with react-test-renderer, but dependency conflicts are tricky.
These are the versions I use:
"@testing-library/jest-native": "^5.4.1",
"@testing-library/react-native": "^11.5.0",
"@tsconfig/react-native": "^2.0.2",
"@types/jest": "^26.0.24",
"@types/react": "^18.0.21",
"@types/react-native": "^0.70.6",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^26.6.3",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "0.72.3",
"react-test-renderer": "18.1.0",
"ts-jest": "^29.0.3",
"typescript": "^4.9.4"
I use react-native (instead of expo) and typescript (instead of js), so there are a few more plugins that you probably don't need, unless your also using TS, but these versions should not conflict with each other.