开玩笑测试升级到本机0.58后中断

时间:2019-03-19 23:32:50

标签: react-native jestjs enzyme react-test-renderer

我使用react-test-rendererenzyme进行的所有测试在升级到本机0.58.6后都中断了

我遇到的错误例如是

  • TypeError: Cannot read property 'default' of undefined
  • Expected value to be truthy, instead received undefined
  • TypeError: Cannot read property 'dive' of undefined
  • TypeError: Cannot read property 'find' of undefined

有人经历过类似的行为吗?我尝试了不同版本的酶,或者开玩笑,但是没有运气。

我的依赖项:

 "dependencies": {
    "firebase": "^5.9.0",
    "prop-types": "^15.6.0",
    "react": "16.6.3",
    "react-native": "0.58.6",
    "react-native-code-push": "^5.5.2",
    "react-native-image-picker": "^0.28.0",
    "react-native-keychain": "^3.0.0",
    "react-native-paper": "^1.12.0",
    "react-native-vector-icons": "^6.4.1",
    "react-navigation": "^1.6.1",
    "react-redux": "^5.0.7",
    "redux": "^3.7.2",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.3.0",
    "yarn": "^1.9.4"
  },
  "devDependencies": {
    "babel-eslint": "^8.2.2",
    "babel-jest": "^23.6.0",
    "enzyme": "^3.8.0",
    "enzyme-adapter-react-16": "^1.7.1",
    "eslint": "^4.18.1",
    "eslint-config-airbnb": "^16.1.0",
    "eslint-plugin-import": "^2.7.0",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-react": "^7.12.3",
    "husky": "^0.14.3",
    "jest": "^23.6.0",
    "jest-fetch-mock": "^2.1.0",
    "lint-staged": "^7.2.2",
    "metro-react-native-babel-preset": "^0.53.1",
    "prettier": "1.10.2",
    "react-dom": "^16.7.0",
    "react-test-renderer": "^16.7.0",
    "redux-mock-store": "^1.5.3"
  },
  "jest": {
    "preset": "react-native",
    "setupFiles": ["<rootDir>/tests/setup.js"],
    "collectCoverageFrom": ["app/**/*.js", "!app/components/index.js"],
    "transform": {
      "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
    },
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-navigation)"
    ]
  }

复制者

https://github.com/defrian/TestProject.git

1 个答案:

答案 0 :(得分:2)

我通过删除

解决了该问题
"transform": {
  "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
},

来自package.json

解决方案在这里https://github.com/facebook/react-native/issues/22175#issuecomment-474786382

我还添加/更新了一些开发依赖项:

"babel-core": "^7.0.0-bridge.0",      (new)
"babel-jest": "24.5.0",               (from "^23.6.0")
"enzyme": "^3.9.0",                   (from "^3.8.0")
"enzyme-adapter-react-16": "^1.11.2", (from "^1.7.1")
"jest": "^24.5.0",                    (from "^23.6.0")
"react-test-renderer": "^16.8.4",     (from "^16.7.0")