简体   繁体   中英

Testing Realm react-native with Jest

Testing React-native Realm with Jest.

I got error message as show below.

Using Jest CLI v0.10.0, jasmine2, babel-jest
 FAIL  __tests__/hackathon-test.js
● Runtime Error
TypeError: Cannot read property 'debugHosts' of undefined
    at Object.<anonymous> (/Users/keen/dev/work_native/spring2016/node_modules/realm/lib/browser/index.js:30:69)
    at Object.<anonymous> (/Users/keen/dev/work_native/spring2016/node_modules/realm/lib/index.js:29:18)
    at Object.<anonymous> (/Users/keen/dev/work_native/spring2016/services/hack-service.js:2:12)
    at Object.<anonymous> (/Users/keen/dev/work_native/spring2016/__tests__/hackathon-test.js:5:18)
npm ERR! Test failed.  See above for more details.
message.

My Package.json of My Project is as shown below.

I posted this issue on Realm.io js too

 {
      "name": "spring2016",
      "version": "0.0.1",
      "private": true,
      "scripts": {
        "start": "node node_modules/react-native/local-cli/cli.js start",
        "test": "jest"
      },
      "dependencies": {
        "react-native": "^0.21.0",
        "react-native-action-button": "^1.1.3",
        "react-native-facebook-login": "^1.0.3",
        "react-native-image-picker": "^0.18.3",
        "react-native-list-popover": "^1.0.5",
        "react-native-material-design": "^0.3.3",
        "react-native-material-kit": "^0.3.0",
        "react-native-vector-icons": "^1.3.2",
        "realm": "^0.11.0"
      },
      "rnpm": {
        "ios": {
          "project": "ios/spring2016.xcodeproj"
        }
      },
  "jest": {
        "setupEnvScriptFile": "<rootDir>/node_modules/react-   native/jestSupport/env.js",
        "testPathIgnorePatterns": [
          "/node_modules/",
          "packager/react-packager/src/Activity/"
        ],
        "testFileExtensions": [
          "js"
        ],
        "unmockedModulePathPatterns": [
          "promise",
          "source-map",
          "<rootDir>/node_modules/react-native",
          "<rootDir>/node_modules/realm"
        ]
      },
      "devDependencies": {
        "babel-jest": "*",
        "babel-preset-react-native": "^1.5.6",
        "jest-cli": "*",
        "react-native": "^0.21.0"
      }
    }

https://gist.github.com/ehrudxo/684b5aeb7211c18237092aece45f29fb

and .babelrc is as show below.

{
"presets": ["react-native"]
}

I'm using babel-jest

When you run rnpm link realm , do you got all the following text?

rnpm-link info Linking realm android dependency 
rnpm-link info Android module realm is already linked 
rnpm-link info Linking realm ios dependency 
rnpm-link info iOS module realm has been successfully linked

Do realm really link iOS? I got the same error because it only link Android when I run rnpm link realm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM