在开玩笑中获取无法找到模块 'react-apollo/test-utils' 错误反应本机
Getting Cannot find module 'react-apollo/test-utils' error in jest teact native
我正在使用 jest 进行单元测试。但是低于错误。我尝试了一些解决方案但仍然相同。请指出我哪里错了。
失败测试/登录-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';
| ^
// package.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/"
]
}
您必须将导入更新为:
import { MockedProvider } from '@apollo/client/testing';
来自Apollo Client 3.0 migration doc:
react-apollo
v3 is an umbrella package that re-exports the following
packages:
@apollo/react-common
@apollo/react-hooks
@apollo/react-components
@apollo/react-hoc
@apollo/react-ssr
@apollo/react-testing
The react-apollo
package has been deprecated, and the functionality
offered by each of the above packages can now be accessed from
@apollo/client
directly:
@apollo/react-hooks
-> now available directly from @apollo/client
@apollo/react-components
-> now available from @apollo/client/react/components
@apollo/react-hoc
-> now available from @apollo/client/react/hoc
@apollo/react-ssr
-> now available from @apollo/client/react/ssr
@apollo/react-testing
-> now available from @apollo/client/testing
我正在使用 jest 进行单元测试。但是低于错误。我尝试了一些解决方案但仍然相同。请指出我哪里错了。
失败测试/登录-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';
| ^
// package.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/"
]
}
您必须将导入更新为:
import { MockedProvider } from '@apollo/client/testing';
来自Apollo Client 3.0 migration doc:
react-apollo
v3 is an umbrella package that re-exports the following packages:
@apollo/react-common
@apollo/react-hooks
@apollo/react-components
@apollo/react-hoc
@apollo/react-ssr
@apollo/react-testing
The
react-apollo
package has been deprecated, and the functionality offered by each of the above packages can now be accessed from@apollo/client
directly:
@apollo/react-hooks
-> now available directly from@apollo/client
@apollo/react-components
-> now available from@apollo/client/react/components
@apollo/react-hoc
-> now available from@apollo/client/react/hoc
@apollo/react-ssr
-> now available from@apollo/client/react/ssr
@apollo/react-testing
-> now available from@apollo/client/testing