gpt4 book ai didi

javascript - Babel 没有使用 Mocha 测试转译 Expo 模块

转载 作者:行者123 更新时间:2023-11-30 20:47:19 26 4
gpt4 key购买 nike

当使用 Mocha 运行单元测试时,我们得到以下 token 异常,它指向 Babel 未转译。

node_modules/expo/src/Expo.js:2
import './environment/validate';
^^^^^^

SyntaxError: Unexpected token import

mocha 测试指向一个从 expo 导入 Constants 的文件

import { Constants } from 'expo'

const config = Constants.manifest.extra

mocha opts 和 babel 是这样配置的

test/mocha.opts

--recursive
--require babel-register

.babelrc

{
"presets": ["babel-preset-expo"],
"env": {
"development": {
"plugins": ["transform-react-jsx-source"]
}
}
}

依赖

{
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-eslint": "^7.2.3",
"chai": "^4.1.2",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^15.0.1",
"eslint-plugin-import": "^2.3.0",
"eslint-plugin-jsx-a11y": "^5.0.3",
"eslint-plugin-react": "^7.0.1",
"jest-expo": "^24.0.0",
"mocha": "^5.0.0",
"react-native-scripts": "1.0.0",
"react-test-renderer": "16.0.0-alpha.6",
"rimraf": "^2.6.2",
"sinon": "^4.2.0"
},
"dependencies": {
"axios": "^0.16.2",
"dot-object": "^1.7.0",
"expo": "^24.0.0",
"google-libphonenumber": "^3.0.5",
"jwt-decode": "^2.2.0",
"lodash": "^4.17.4",
"moment": "^2.19.3",
"prop-types": "^15.5.10",
"react": "16.0.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-24.0.0.tar.gz",
"react-native-google-places-autocomplete": "^1.3.6",
"react-native-modal": "^4.1.1",
"react-native-modal-datetime-picker": "^4.12.0",
"react-native-swipeable": "^0.6.0",
"react-native-vector-icons": "^4.2.0",
"react-navigation": "^1.0.0-beta.21",
"react-redux": "^5.0.5",
"redux": "^3.6.0",
"redux-devtools": "^3.4.0",
"redux-devtools-dock-monitor": "^1.1.2",
"redux-devtools-log-monitor": "^1.3.0",
"redux-logger": "^3.0.6",
"redux-saga": "^0.15.3",
"redux-thunk": "^2.2.0",
"styled-components": "^2.0.1"
}
}

我们在运行

yarn mocha

最佳答案

我刚刚遇到了类似的错误 - 我的许多套件在我在单个文件中使用 Expo.AuthSession 后会崩溃。

我通过添加解决了我的问题

jest.mock('博览会', () => ({
授权 session :{
getRedirectUrl: jest.fn(),
},
}));

到我的全局模拟文件。

关于javascript - Babel 没有使用 Mocha 测试转译 Expo 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48570838/

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