gpt4 book ai didi

javascript - React Native Web 测试 Jest 错误 : ReferenceError: __DEV__ is not defined

转载 作者:行者123 更新时间:2023-12-03 20:50:42 25 4
gpt4 key购买 nike

很多人似乎都经历过这个问题的一个版本,但之前的解决方案似乎都不适合我。我的应用是用 CRA 和 React Native Web 构建的。我正在测试基于 View from react native 的组件的点击行为。我试图从 '@testing-library/react-native' 导入 { fireEvent },因为来自 @testing-library/react 的 fireEvent 不起作用但会引发此错误:ReferenceError: 开发 没有定义
包.json

{
"name": "writual",
"version": "0.1.0",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-free": "^5.12.1",
"@fortawesome/fontawesome-svg-core": "^1.2.27",
"@fortawesome/free-solid-svg-icons": "^5.12.1",
"@fortawesome/react-fontawesome": "^0.1.8",
"@n8tb1t/use-scroll-position": "^1.0.43",
"@react-mock/localstorage": "^0.1.2",
"@react-native-community/masked-view": "^0.1.7",
"@react-pdf/renderer": "^1.6.8",
"aphrodite": "^2.4.0",
"babelify": "^10.0.0",
"blob-stream": "^0.1.3",
"browserify": "^16.5.0",
"draft-js": "^0.11.4",
"draft-js-plugins-editor": "^3.0.0",
"draft-js-static-toolbar-plugin": "^3.0.1",
"expo": "^36.0.2",
"expo-cli": "^3.11.9",
"firebase": "^7.9.1",
"g": "^2.0.1",
"lodash.debounce": "^4.0.8",
"mutationobserver-shim": "^0.3.7",
"pdfkit": "^0.10.0",
"react": "^16.13.1",
"react-art": "^16.12.0",
"react-dom": "^16.11.0",
"react-fns": "^1.4.0",
"react-google-button": "^0.7.0",
"react-google-login": "^5.1.1",
"react-native": "^0.61.5",
"react-native-draggable": "^3.3.0",
"react-native-material-dropdown": "^0.11.1",
"react-native-movable-view": "^1.0.3",
"react-native-multi-select-picker": "^1.0.11",
"react-native-multiple-select": "^0.5.5",
"react-native-popup-menu": "^0.15.7",
"react-native-responsive-screen": "^1.4.0",
"react-native-sectioned-multi-select": "^0.7.7",
"react-native-vector-icons": "^6.6.0",
"react-native-web": "^0.12.1",
"react-pdfmake": "^0.2.0",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.3.1",
"react-with-firebase-auth": "^1.3.0",
"recyclerlistview": "^3.0.0",
"socket.io": "^2.3.0",
"typescript": "^3.7.2"
},
"scripts": {
"start": "react-scripts start",
"build-web": "react-scripts build",
"test-web": "react-scripts test",
"eject-web": "react-scripts eject",
"start-native": "expo start",
"android": "expo android",
"ios": "expo ios",
"build:ios": "expo build:ios",
"build:android": "expo build:android"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@testing-library/jest-dom": "^5.11.1",
"@testing-library/react": "^10.4.7",
"@testing-library/react-native": "^5.0.3",
"@testing-library/user-event": "^12.0.12",
"babel-plugin-module-resolver": "^4.0.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-react-jsx-source": "^6.22.0",
"babel-preset-expo": "^8.0.0",
"css-loader": "^3.6.0",
"enzyme": "^3.8.0",
"enzyme-adapter-react-16": "^1.7.1",
"enzyme-to-json": "^3.3.5",
"firebase-mock": "^2.3.2",
"mock-local-storage": "^1.1.14",
"style-loader": "^1.2.1"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"jest": {
"transformIgnorePatterns": [
"node_modules/(?!(react-native|react-native-responsive-screen|draft-js-static-toolbar-plugin|react-google-button')/)"
],
"moduleFileExtension": [
"js",
"json",
"jsx",
"ts",
"tsx",
"node"
],
"moduleNameMapper": {
"^react-native$": "react-native-web"
},
"globals": {
"DEV": true
},
"verbose": true,
"preset": "react-native"
}
}
babelrc
{
"presets": [
"babel-preset-expo"
],
"env": {
"development": {
"plugins": [
"transform-object-rest-spread",
"transform-react-jsx-source",
]
}
},
"plugins": [
[
"module-resolver",
{
"alias": {
"^react-native$": "react-native-web",
}
},
]
]
}

最佳答案

看来你有DEV而不是 __DEV__在您的 package.json :

// ...
"jest": {
// ...
"globals": {
"__DEV__": true
},
// ...
}
// ...

关于javascript - React Native Web 测试 Jest 错误 : ReferenceError: __DEV__ is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63046597/

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