Jest 在 react-native-modalize 上失败了?

Posted

技术标签:

【中文标题】Jest 在 react-native-modalize 上失败了?【英文标题】:Jest is failing on react-native-modalize? 【发布时间】:2021-12-16 23:20:00 【问题描述】:

我的笑话脚本在 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,

pacakge.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 版本,它工作正常。

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

【问题讨论】:

【参考方案1】:

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

正如您在 node_modules/react-native-modalize/lib/utils/devices.js 中看到的那样,它与 reactNativeVersion 有关。

【讨论】:

以上是关于Jest 在 react-native-modalize 上失败了?的主要内容,如果未能解决你的问题,请参考以下文章

带有嵌套 ScrollView 的可滑动 React-native-modal

jest中的mock,jest.fn()jest.spyOn()jest.mock()

jest中的mock,jest.fn()jest.spyOn()jest.mock()

jest中的mock,jest.fn()jest.spyOn()jest.mock()

在使用 jest 的 vue 测试中找不到模块“@jest/globals”

如何在 jest 测试用例 +VueJS +Jest 中更改 $route