找不到来自'react-native.js'w/Jest的模块'ReactNative'

Kyl*_*cot 21 javascript reactjs jestjs react-native

我正在尝试使用jest(v20.0.0)w /我的React Native应用程序(v0.42.0)但是当我运行时,yarn jest我收到以下错误:

yarn jest v0.27.5
$ jest
 FAIL  __tests__/routing/router-test.js
  ? Test suite failed to run

    Cannot find module 'ReactNative' from 'react-native.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:179:17)
      at Object.<anonymous> (node_modules/react-native/Libraries/react-native/react-native.js:188:25)
Run Code Online (Sandbox Code Playgroud)

这是jest我的一部分package.json

  "jest": {
    "testPathIgnorePatterns": [
      "/node_modules/"
    ],
    "transformIgnorePatterns": [
      "node_modules/(?!react-native|react-native-geocoding)/"
    ],
    "globals": {
      "__DEV__": false
    },
    "collectCoverage": false
  },
Run Code Online (Sandbox Code Playgroud)

更新#1

这是失败的测试文件(我删除了除了之外的所有内容,import并且错误仍然存​​在).

import 'react-native';
import React from 'react';

describe('Router', () => {

});
Run Code Online (Sandbox Code Playgroud)

AJc*_*dez 0

这是一个适合我的配置。

  "devDependencies": {
    "babel-jest": "21.0.2",
    "babel-plugin-module-resolver": "2.7.1",
    "babel-preset-es2015": "6.24.1",
    "babel-preset-react-native": "1.9.1",
    "jest": "21.0.2"
  },
  "jest": {
    "preset": "react-native",
    "automock": false,
    "testMatch": [
      "<rootDir>/source/**/__tests__/*.js"
    ],
    "moduleFileExtensions": [
      "js",
      "jsx"
    ],
    "moduleDirectories": [
      "node_modules",
      "<rootDir>/source"
    ],
    "globals": {
      "__DEV__": true
    }
  },
Run Code Online (Sandbox Code Playgroud)