越来越无法找到模块'的反应-阿波罗的/试验工具'错误在开玩笑teact地

0

的问题

我做的单元的测试,测试采用玩笑。 但是,得到以下错误。我尝试了一些解决方案,但仍然相同。 请给我建议,我错了。

失败 测试/login-test.js ●测试未能运行

Cannot find module 'react-apollo/test-utils' from 'login-test.js'

  3 | import Login from '../app/components/Login';
  4 | import LoginContainer from '../app/components/container/LoginContainer';
> 5 | import { MockedProvider } from 'react-apollo/test-utils';
    | ^

//软件包。json

"devDependencies": {
    "@babel/core": "7.9.0",
    "@babel/runtime": "7.9.2",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-cli": "^6.26.0",
    "babel-jest": "^24.9.0",
    "eslint": "6.8.0",
    "jest": "^24.9.0",
    "jetifier": "^1.6.4",
    "metro-react-native-babel-preset": "^0.56.0",
    "react-test-renderer": "16.8.6"
  },
  "jest": {
    "preset": "react-native",
    "collectCoverage": true,
    "coverageReporters": [
      "json",
      "html"
    ],
    "setupFiles": [
      "./jestSetupFile.js",
      "./node_modules/react-native-gesture-handler/jestSetup.js"
    ],
    "transformIgnorePatterns": [
      "node_modules/(?!react-native|native-base-shoutem-theme|@shoutem/animation|@shoutem/ui|tcomb-form-native|@react-native-community/async-storage|native-base/node_modules/react-native-vector-icons|react-navigation|@codler/react-native-keyboard-aware-scroll-view|react-native-device-info|rn-sliding-up-panel|@react-native-community/masked-view|@react-navigation/bottom-tabs/node_modules/react-native-iphone-x-helper|rn-tooltip|@react-native-community/datetimepicker|node_modules/react-native-tab-view|jsbarcode|@react-native-community/art|@react-native-firebase/analytics|@react-native-firebase|jail-monkey|@dudigital/react-native-zoomable-view/src/ReactNativeZoomableView|@haskkor/react-native-pincode|Platform)"
    ]
  },
  "rnpm": {
    "assets": [
      "./assets/fonts/"
    ]
  }
graphql jestjs react-apollo react-native
2021-11-23 06:48:02
1

最好的答案

1

你需要更新的进口:

import { MockedProvider } from '@apollo/client/testing';

阿波罗客户3.0移徙doc:

react-apollo v3是一个伞式包装,重新出口下面 软件包:

  • @apollo/react-common
  • @apollo/react-hooks
  • @apollo/react-components
  • @apollo/react-hoc
  • @apollo/react-ssr
  • @apollo/react-testing

react-apollo 包已经被弃用和功能 提供上述的每个包件现在可以访问 @apollo/client 直接:

  • @apollo/react-hooks ->的现在可以直接从 @apollo/client
  • @apollo/react-components ->的现在可以从 @apollo/client/react/components
  • @apollo/react-hoc ->的现在可以从 @apollo/client/react/hoc
  • @apollo/react-ssr ->的现在可以从 @apollo/client/react/ssr
  • @apollo/react-testing ->的现在可以从 @apollo/client/testing
2021-11-23 10:06:20

感谢您的时间,但仍然同样的错误●测试失败的运行,无法找到模块'@阿波罗/客户/测试'
Abhigyan Gaurav

你确定你已经安装@阿波罗/客户? 尝试 npm install @apollo/clientyarn add @apollo/client 如果你使用纱
Fraction

它的工作非常感谢
Abhigyan Gaurav

我不确定是哪个版本的阿波罗你的客户正在使用但我假设它是v3(@apollo/client),因为你说你使用 react-apollo": "3.1.5"但你使用v2(apollo-client,这是一个旧版本)你需要安装 npm install [email protected] --save 并保持 import { MockedProvider } from 'react-apollo/test-utils';
Fraction

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................