我已使用以下命令更新package.json
“ ^。((?! Saga)。)* \。js $”:“ /node_modules/react-native/jest/preprocessor.js”,
但是,使用ES7语法编写的每个组件都会停止工作,例如
export default class Test extends Component {
state = { test: '' }
testFunc = () => {}
}
答案 0 :(得分:0)
通过更新我的.babelrc解决了
{
"presets": ["module:metro-react-native-babel-preset"],
"env": {
"test": {
"presets": ["react-native"]
}
}
}
答案 1 :(得分:-1)
(1)我使用.babelrc.js而不是.babelrc并添加以下代码段:
'ele2'
(2)在您的devDependencies中添加“ babel-preset-react-native”:“ ^ 5” (3)将package.json中的测试脚本更新为
let presets = ["module:metro-react-native-babel-preset"];
let plugins = [];
if (process.env['ENV'] === 'test') {
presets = ["babel-preset-react-native"];
plugins = ["jest-hoist"];
}
module.exports = { presets, plugins };
这样做的原因是在不同的ENV中使用不同的babel预设