更新到React Native 0.60.4,Jest失败,存在Invariant Violation:__fbBatchedBridgeConfig未设置

yyhrrdl8  于 2023-11-21  发布在  React
关注(0)|答案(1)|浏览(105)

从RN0.59.10更新到RN0.60.4后,我的一些jest测试失败,
第一个月
我不确定这是否与预处理器有关。我真的找不到关于fbBatchedBridgeConfig的有用信息。
我不确定测试是否失败,因为他们已经切换到自动链接软件包。
package.json

"dependencies": {
    "@react-native-community/async-storage": "1.5.0",
    "apollo-cache-inmemory": "1.6.2",
    "apollo-cache-persist": "0.1.1",
    "apollo-client": "2.6.3",
    "apollo-link-error": "1.1.11",
    "apollo-link-http": "1.5.15",
    "apollo-link-retry": "2.2.14",
    "apollo-utilities": "1.3.2",
    "buffer": "5.2.1",
    "bugsnag-react-native": "2.21.0",
    "enzyme": "3.5.1",
    "enzyme-adapter-react-16": "1.5.0",
    "formik": "1.3.1",
    "graphql": "14.4.2",
    "graphql-tag": "2.10.1",
    "hoist-non-react-statics": "3.3.0",
    "immer": "3.1.3",
    "intl": "1.2.5",
    "moment": "2.24.0",
    "pre-commit": "1.2.2",
    "prop-types": "15.7.2",
    "react": "16.8.6",
    "react-apollo": "2.5.8",
    "react-intl": "2.9.0",
    "react-native": "0.60.4",
    "react-native-calendar-events": "1.7.0",
    "react-native-camera-kit": "7.3.7",
    "react-native-code-push": "5.6.0",
    "react-native-config": "0.11.7",
    "react-native-contacts": "2.1.1",
    "react-native-device-info": "2.1.2",
    "react-native-fast-image": "7.0.0",
    "react-native-firebase": "5.2.2",
    "react-native-gesture-handler": "1.1.3",
    "react-native-keyboard-accessory": "0.1.9",
    "react-native-keyboard-aware-scroll-view": "0.8.0",
    "react-native-navbar": "2.1.0",
    "react-native-permissions": "1.1.1",
    "react-native-photo-view": "1.5.2",
    "react-native-restart": "0.0.9",
    "react-native-safe-area": "0.5.0",
    "react-native-snap-carousel": "3.8.0",
    "react-native-swipe-list-view": "1.5.8",
    "react-native-vector-icons": "6.6.0",
    "react-native-webview": "5.12.1",
    "react-native-zendesk-support": "1.0.9",
    "react-navigation": "3.3.0",
    "recompose": "0.30.0",
    "yup": "0.27.0"
  },
  "devDependencies": {
    "@babel/cli": "7.4.4",
    "@babel/core": "7.5.0",
    "@babel/plugin-proposal-optional-chaining": "7.0.0",
    "@babel/preset-flow": "7.0.0",
    "babel-core": "7.0.0-bridge.0",
    "babel-eslint": "10.0.1",
    "babel-jest": "24.1.0",
    "babel-plugin-module-resolver": "3.1.1",
    "babel-plugin-react-intl": "3.0.0",
    "babel-plugin-transform-flow-strip-types": "6.22.0",
    "eslint": "5.10.0",
    "eslint-config-airbnb": "17.1.0",
    "eslint-config-prettier": "3.3.0",
    "eslint-import-resolver-babel-module": "5.0.0-beta.1",
    "eslint-plugin-import": "2.14.0",
    "eslint-plugin-jsx-a11y": "6.1.2",
    "eslint-plugin-react": "7.11.1",
    "eslint-plugin-react-native": "3.5.0",
    "fs-extra": "2.1.2",
    "jest": "24.1.0",
    "jest-fetch-mock": "1.6.6",
    "jest-react-native": "18.0.0",
    "jetifier": "^1.6.3",
    "jsdom": "15.1.1",
    "lint-staged": "7.2.2",
    "metro-react-native-babel-preset": "0.53.1",
    "prettier": "1.18.2",
    "react-dom": "16.8.6",
    "react-test-renderer": "16.8.6",
    "schedule": "0.5.0",
    "sinon": "7.3.2"
  },
  "jest": {
    "preset": "react-native",
    "timers": "fake",
    "testRegex": "\\.test\\.js$",
    "setupFilesAfterEnv": [
      "<rootDir>/enzymeConfig.js"
    ],
    "automock": false,
    "setupFiles": [
      "<rootDir>/scripts/setupJest.js"
    ],
    "transformIgnorePatterns": [
      "node_modules/(?!(@react-native-community|react-native))"
    ],
    "transform": {
      "^.+\\.js$": "<rootDir>/scripts/preprocessor.js"
    },
    "moduleNameMapper": {
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/js/__mocks__/fileMock.js"
    },
    "moduleDirectories": [
      "node_modules"
    ],
    "collectCoverageFrom": [
      "js/**/*.{js}",
      "!**/node_modules/**"
    ]
  }

字符串

gorkyyrv

gorkyyrv1#

在我的例子中,它是由@react-navigation/native引起的,就像下面的代码一样

import { NavigationContainer } from "@react-navigation/native";

function App() {
  const [pressCount, incrementCount] = useReducer(
    (currentCount: number) => currentCount + 1,
    0,
  );
  return (
    <NavigationContainer>
...
}

字符串
我得到了

Invariant Violation: __fbBatchedBridgeConfig is not set, cannot invoke native modules                                                                 
                                                                                                                                                          
       6 |                                                                                                                                                
       7 | it("should load", async () => {                                                                                                                
    >  8 |   render(<App />);


但我还没有找到一个很好的解决办法。

相关问题