当使用Mocha运行单元测试时,我们得到以下令牌异常,指出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
答案 0 :(得分:1)
我刚遇到类似的错误 - 在单个文件中使用?"INSERT INTO MobileDeviceUserList(sUser, sDevice, sMobileNumber, sIMEINumber, sSerialNumber, sAccessories, sNewSIMNumber, sComments, sRecorded) " & _
"VALUES (" & Me.cboDevice & ",'" & Me.cboAccessories & ",'" & Me.txtUser & ",'" & Me.txtNumber & ",'" & Me.txtIMEI & ",'" & Me.txtSerial & ",'" & Me.txtNEWSIM & ",'" & Me.recRecorded & ",'" & _
Me.txtComment & "')"
后,我的许多套件都会中断。
我通过添加
解决了我的问题 Expo.AuthSession
到我的全局模拟文件。