Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Invariant Violation: Native module cannot be null. #137

Open
miguelc1221 opened this issue Jun 9, 2017 · 6 comments
Open

Invariant Violation: Native module cannot be null. #137

miguelc1221 opened this issue Jun 9, 2017 · 6 comments
Labels

Comments

@miguelc1221
Copy link

Hey, not sure if this is the best place to ask but i just started using react-native-mock and I keep getting this error which I am not sure how to fix and might be related to the library.


    Invariant Violation: Native module cannot be null.
      
      at invariant (node_modules/fbjs/lib/invariant.js:44:7)
      at RCTNetworking.NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:32:1)
      at new RCTNetworking (node_modules/react-native/Libraries/Network/RCTNetworking.ios.js:23:165)
      at Object.<anonymous> (node_modules/react-native/Libraries/Network/RCTNetworking.ios.js:59:16)
      at Object.<anonymous> (node_modules/react-native/Libraries/Network/XMLHttpRequest.js:15:19)```
@RealOrangeOne
Copy link
Owner

Looking at that stack trace, it probably is a react-native-mock bug. However it's very difficult to tell what the issue is with just that stack trace. Can you try and reproduce it more clearly with an example, or provide a stack trace

@miguelc1221
Copy link
Author

I'll try to reproduce in the meantime here is some more info. The above is what I keep getting when I try to run jest, so currently can run any tests.

What led me to use react-native-mock was the fact that I couldn't mock NativeEventEmitter which we are using.

dependencies

  "dependencies": {
    "babel-plugin-transform-decorators-legacy": "1.3.4",
    "bugsnag-react-native": "2.2.0",
    "class-autobind": "^0.1.4",
    "color": "0.11.3",
    "lodash": "4.15.0",
    "moment": "2.17.1",
    "react": "15.4.2",
    "react-native": "0.42.3",
    "react-native-calendar": "0.10.0",
    "react-native-extended-stylesheet": "0.3.0",
    "react-native-fs": "2.1.0-rc.1",
    "react-native-keyboard-aware-scroll-view": "0.2.3",
    "react-native-material-kit": "0.4.1",
    "react-native-sensitive-info": "3.0.2",
    "react-native-snap-carousel": "1.2.0",
    "react-native-svg": "5.1.5",
    "react-native-vector-icons": "2.1.0",
    "react-redux": "4.4.5",
    "redux": "3.6.0",
    "redux-async-action": "0.0.4",
    "redux-thunk": "2.1.0",
    "victory-native": "0.7.0"
  },
  "devDependencies": {
    "babel-eslint": "6.1.2",
    "babel-jest": "20.0.3",
    "enzyme": "2.8.2",
    "enzyme-to-json": "1.5.1",
    "eslint": "3.7.1",
    "eslint-config-airbnb": "10.0.1",
    "eslint-plugin-import": "1.16.0",
    "eslint-plugin-jsx-a11y": "2.2.3",
    "eslint-plugin-react": "6.4.1",
    "gradle-to-js": "0.2.5",
    "husky": "0.11.9",
    "jest": "20.0.4",
    "localenv": "0.2.2",
    "react-addons-test-utils": "15.4.2",
    "react-dom": "15.4.4",
    "react-test-renderer": "15.4.2",
    "redux-mock-store": "1.2.3",
    "request": "2.81.0",
    "react-native-mock": "0.3.1"
  }

Jest config

"jest": {
    "preset": "react-native",
    "verbose": true,
    "setupFiles": ["./jestsetup.js"],
    "snapshotSerializers": [
      "enzyme-to-json/serializer"
    ],
    "transformIgnorePatterns": [
      "node_modules/(?!react-native|bugsnag-react-native)/"
    ]
  },

jestSetup.js

require('react-native-mock/mock');

jest.mock('NativeModules', () => ({
  Environment: {
    BUGSNAG_API_KEY: 'ApiKey',
  },
}));

@RealOrangeOne
Copy link
Owner

Hmm, interesting. I'd never considered people wanting to use react-native-mock with jest, but i guess it should work. But yes please try and narrow down exactly why it happens. It's possible it's some conflicting between react-native-mock and jest's builtin mock

@skathayat
Copy link

@miguelc1221 I am also experiencing the same issue. Have you found a solution to this?

@doniyor2109
Copy link

+1

@keithmattix
Copy link

I get this because KeyboardManager is not included in the mocked native modules

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants