react-nativejestjs

TypeError: Cannot read property 'ReactCurrentOwner' of undefined


I'm running the unit tests in a react-native app I'm developing and three of them are failing with this message:

TypeError: Cannot read property 'ReactCurrentOwner' of undefined

The error does not seem to be caused by my code, but either by react-test-renderer (in two tests) and in enzyme-adapter-react-16 (in one test).

This was an expo app and the unit tests were running. I then ejected. I replaced

"jest": {
  "preset": "jest-expo"
},

with

"jest": {
  "preset": "react-native"
},

and all my other tests are running. The three failing tests are the only ones that use react-test-renderer and enzyme-adapter-react-16.

I've tried (many times) removing node_modules and reinstalling. Here are the versions I'm using:

"devDependencies": {
  "babel-preset-react-native-stage-0": "^1.0.1",
  "deep-freeze": "^0.0.1",
  "enzyme": "^3.1.1",
  "enzyme-adapter-react-16": "^1.0.4",
  "eslint": "^4.9.0",
  "jest": "^21.2.1",
  "react-dom": "^16.0.0",
  "react-test-renderer": "^16.0.0"
},
"scripts": {
  "start": "react-native start",
  "android": "react-native run-android",
  "ios": "react-native run-ios",
  "test": "jest"
},
"jest": {
  "preset": "react-native"
},
"dependencies": {
  "assert": "^1.4.1",
  "react": "16.0.0",
  "react-native": "^0.50.1",
  "react-redux": "^5.0.6",
  "redux": "^3.7.2",
  "yarn": "^1.3.2"
}*

Solution

  • For the benefit of others who have the same problem: it was fixed when I cleaned up my global node_modules and left react, react-native, and some other stuff only in the project's node_modules.