Jest тесты ломаются после обновления до реакции-родной 0,58 - PullRequest
2 голосов
/ 20 марта 2019

все мои тесты, использующие react-test-renderer или enzyme перерыв после обновления до реагирующей нативной 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 Ответ

2 голосов
/ 24 марта 2019

Я решил проблему, удалив

"transform": {
  "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
},

от package.json

найденное здесь решение https://github.com/facebook/react-native/issues/22175#issuecomment-474786382

Я также добавил / обновил некоторые зависимости dev:

"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")
...