【发布时间】:2019-02-20 15:26:07
【问题描述】:
在我的 react-native 项目上运行测试套件时,不断出现以下错误。
/.../node_modules/@expo/react-native-action-sheet/ActionSheet.ios.js:3
import React from 'react';
^^^^^
SyntaxError: Unexpected identifier
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
at Object.<anonymous> (node_modules/@expo/react-native-action-sheet/index.js:1:45)
以下是使用的测试代码。这是一个简单的 Jest 快照测试
//ContactList Tests
import React from 'react';
import renderer from 'react-test-renderer';
import ContactList from '../components/ContactList';
//ContactList Snapshot
test('renders correctly', () => {
const tree = renderer.create(<ContactList />).toJSON();
expect(tree).toMatchSnapshot();
});
我正在运行 react-native 版本 0.55.4 和 Jest 版本 23.6.0
【问题讨论】:
-
你的 babel 配置是什么样的,它们位于什么文件中?
-
这是来自 package.json 的 babel 配置
-
"devDependencies": { "babel-jest": "23.6.0", "babel-preset-react-native": "4.0.1", "jest": "^23.6.0 ", "react-test-renderer": "16.3.1" },
-
我也希望获得您的
.babelrc或babel.config.js或类似的内容。 -
对不起,这是我的 .babelrc 文件 { "presets": ["react-native"] }
标签: javascript react-native jestjs react-native-ios