Reactjs React Native中的Jest和React导航出错

Reactjs React Native中的Jest和React导航出错,reactjs,react-native,jestjs,react-navigation,Reactjs,React Native,Jestjs,React Navigation,我在使用玩笑进行单元测试时遇到问题: 不变冲突:本机模块不能为null at invariant (node_modules/fbjs/lib/invariant.js:42:15) at new NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:35:7) at Object.<anonymous> (node_modules/react-

我在使用玩笑进行单元测试时遇到问题:

不变冲突:本机模块不能为null

  at invariant (node_modules/fbjs/lib/invariant.js:42:15)
  at new NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:35:7)
  at Object.<anonymous> (node_modules/react-native-google-analytics-bridge/src/Helpers/FunctionCallTagHandler/index.io
at invariant(node_modules/fbjs/lib/invariant.js:42:15)
在新的NativeEventMitter(node_modules/react native/Libraries/EventEmitter/nativeEventMitter.js:35:7)
反对。(node_modules/react原生谷歌分析桥/src/Helpers/FunctionCallTagHandler/index.io
s、 (js:16:37) 反对。(node_modules/react原生谷歌分析桥/src/GoogleTagManager.js:2:1)


我之前也遇到过同样的问题。可以建议一种解决方法。这个问题只发生在iOS上的
react native google analytics bridge
上,因此您可以将jest默认平台切换到Android

在您的
package.json中

"jest": {
    "preset": "react-native",
    "haste": {
      "defaultPlatform": "android",
      "platforms": [
        "android",
        "ios"
      ],
      "providesModuleNodeModules": [
        "react",
        "react-native"
      ]
    }
  }

“谢谢”我还有其他错误:TypeError:无法读取未定义NotificationsComponent.Object..NotificationsComponent.getInitialNotification(node_modules/react native push notification/component/index.android.js:20:31)在Object..Notifications.callNative的属性“getInitialNotification”(node_modules/react native push notification/index.js:39:10)在Object..Notifications.popInitialNotification(node_modules/react native push notification/index.js:302:7)当我尝试此解决方案时,我得到了以下错误:
setup.js:babel plugin jest hugh:jest.mock()的模块工厂'不允许引用任何超出范围的变量。变量访问无效:console
但是,我的setup.js文件没有引用console。我很困惑。