gpt4 book ai didi

javascript - 找不到模块 'setupDevtools' React-Native

转载 作者:搜寻专家 更新时间:2023-11-01 04:34:50 25 4
gpt4 key购买 nike

我收到以下错误:

Cannot find module 'setupDevtools' from 'setup.js'

at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:169:17

我的 JSON.package 文件如下所示:

{
"name": "MiBase",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"babel-preset-env": "^1.7.0",
"i": "^0.3.6",
"jest-react-native": "^18.0.0",
"react": "16.3.1",
"react-native": "0.55.3",
"react-native-datepicker": "^1.7.2",
"react-native-image-picker": "^0.26.7",
"react-native-ui-xg": "0.0.6",
"react-navigation": "^1.5.11"
},
"devDependencies": {
"babel-jest": "^22.4.3",
"babel-preset-react-native": "3.0.0",
"jest": "22.4.3",
"react-test-renderer": "^16.3.1"
},
"jest": {
"preset": "react-native",
"moduleNameMapper": {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__tests__/loginTest.js",
"\\.(css|sass)$": "<rootDir>/__tests__/loginTest.js"
},
"transformIgnorePatterns": [
"node_modules"
],
"coveragePathIgnorePatterns": [
"node_modules"
],
"modulePathIgnorePatterns": [
"node_modules"
]
}

我的测试文件如下所示:

// __tests__/loginTest.js
import 'react-native';
import React from 'react';
import HomeSreen from '../App';

import renderer from 'react-test-renderer';

test('renders correctly', () => {
const tree = renderer.create(<LoginScreen />).toJSON();
expect(tree).toMatchSnapshot();
});

我对 React Native 非常陌生,甚至对使用它进行测试也很陌生。我所学到的或试图解决这个问题的一切都来自这三个地方:

https://facebook.github.io/jest/docs/en/tutorial-react-native.html Jest Cannot find module 'setupDevtools' from 'setup.js' Jest - Cannot find module 'setupDevtools' from 'setup.js'

我在类中还有其他函数,目前我不想测试这些函数。我只是想测试 GUI 功能并且一切都正确显示。这些函数用于处理 http 响应和 JSON 解析。

最佳答案

在我的例子中,我使用 TypeScript,我遇到了同样的错误,并使用以下 package.json 配置修复它:

"dependencies": {
"react": "^16.3.0-alpha.1",
"react-native": "0.54.3"
},
"devDependencies": {
"@types/jest": "^22.2.2",
"@types/react": "^16.0.41",
"@types/react-native": "^0.52.19",
"@types/react-test-renderer": "^16.0.1",
"babel-jest": "22.4.3",
"babel-preset-react-native": "4.0.0",
"jest": "22.4.3",
"react-addons-test-utils": "^15.6.2",
"react-native-mock": "^0.3.1",
"react-native-typescript-transformer": "^1.2.3",
"react-test-renderer": "^16.3.0-alpha.1",
"ts-jest": "^22.4.2",
"typescript": "^2.8.1"
},
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\\.(js)$": "<rootDir>/node_modules/babel-jest",
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"testPathIgnorePatterns": [
"\\.snap$",
"<rootDir>/node_modules/",
"<rootDir>/lib/"
],
"cacheDirectory": ".jest/cache"
}

您可以在 this repo 上找到此配置

希望对您有所帮助。

关于javascript - 找不到模块 'setupDevtools' React-Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50577375/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com