首页 > 解决方案 > Jest 在 react-native-modalize 上失败了?

问题描述

我的笑话脚本在 react-native-modalize 上失败了。为什么 jest 在这一点上失败了

错误

 ● Test suite failed to run

    TypeError: Cannot read property 'minor' of undefined

      at Object.<anonymous> (node_modules/react-native-modalize/lib/utils/devices.js:20:76)
      at Object.<anonymous> (node_modules/react-native-modalize/lib/utils/use-dimensions.js:25:19)

我的 package.json 在下面,

包装.json

{
  "name": "vendor",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "npx react-native run-android",
    "ios": "react-native run-ios"
  },
  "dependencies": {
    "@jest/globals": "^27.0.6",
    "@react-native-async-storage/async-storage": "^1.15.6",
    "react-native-modal": "^12.1.0",
    "react-native-modalize": "^2.0.8",
  },
  "devDependencies": {
    "@babel/core": "^7.15.0",
    "@babel/runtime": "^7.15.3",
    "@codler/react-native-keyboard-aware-scroll-view": "1.0.1",
    "@react-native-community/eslint-config": "^3.0.0",
    "@testing-library/jest-native": "^4.0.2",
    "@testing-library/react-native": "^7.2.0",
    "@typescript-eslint/eslint-plugin": "^4.29.2",
    "@typescript-eslint/parser": "^4.29.2",
    "babel-eslint": "^10.1.0",
    "babel-jest": "^27.0.6",
    "detox": "^17.14.9",
    "enzyme": "^3.11.0",
    "enzyme-adapter-react-16": "^1.15.6",
    "jest": "^26.6.3",
    "jest-circus": "^26.6.0",
    "jsdom": "17.0.0",
    "jsdom-global": "3.0.2",
    "metro-react-native-babel-preset": "^0.66.2",
    "prettier": "^2.3.2",
    "react-native-rename": "^2.9.0",
    "react-test-renderer": "17.0.2"
  },
  "jest": {
    "coverageReporters": [
      "text"
    ],
    "reporters": [
      "default",
      "jest-junit"
    ],
    "preset": "react-native",
    "setupFilesAfterEnv": [
      "@testing-library/jest-native/extend-expect"
    ],
    "transformIgnorePatterns": [
      "/node_modules/(?!react-native)/.+"
    ],
    "setupFiles": [
      "./node_modules/react-native-gesture-handler/jestSetup.js"
    ]
  },
  "jest-junit": {
    "output": "output/coverage/junit/junit.xml",
    "usePathForSuiteName": "true"
  }
}

我在升级之前升级了 react-native 版本,它工作正常。

为什么会失败?我应该降级任何软件包还是我错过了什么?

标签: react-nativetestingjestjs

解决方案


它已在合并中修复。所以,继续更新你的版本react-native-modalize

正如您可能已经看到的,node_modules/react-native-modalize/lib/utils/devices.js它与 reactNativeVersion 有关。


推荐阅读