neuberoliveira/react-native-gps-state

Invariant Violation: Native module cannot be null.

Closed this issue · 4 comments

getting this Invariant Violation: Native module cannot be null error in test cases,after installing this library.

"jest": {
    "moduleNameMapper": {
      "\\.(styles)$": ""
    },
    "collectCoverage": true,
    "testResultsProcessor": "jest-sonar-reporter",
    "coverageReporters": [
      "json",
      "html",
      "lcov",
      "text"
    ],
    "collectCoverageFrom": [
      "src/**/*.{js,jsx}"
    ],
    "verbose": true,
    "preset": "react-native",
    "moduleFileExtensions": [
      "js"
    ],
    "transform": {
      "^.+\\.(js)$": ""
    },
    "transformIgnorePatterns": [
      "/node_modules/(?!react-native|react-navigation)"
    ],
    "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(js)$",
    "setupFiles": [
      "./setup.js"
    ]
  }
}

What version are you using?
What platform?
Did you link it with react-native link react-native-gps-state

This normally happen when rn cant find the native code, something goes wrong when install or link dosent work for some reason.

@neuberoliveira : i have linked it,and got successful message for both ios and android.
versions i'm using are mentioned below.please support on urgent basis as i'm failing in mostly half of my test suits with the same error.

react-native-gps-state: ^1.2.0,
react-native: 0.57.1,

image

As far as i know, tests run on a node env only, so theres no way an android/ios native code can run or load, hence the error.

I think you would need to mock it.

In my current app i try to implement tests one time, but theres so many native code i would need to mock that i giveup.

i tried mocking the function by making a separate file in my project as setup.js, results in occurrence of new error linked with some internal library rn-fetch-blob.

image