语法错误:const 声明中缺少初始值设定项 [英] SyntaxError: Missing initializer in const declaration
问题描述
我正在我的 react native expo 应用程序中使用 react-native-testing-library
(我使用该库的第一步)编写一个简单的测试.但是我收到了一个来自 react-native
代码库本身内部某个地方的混淆错误.要么我的代码有问题,要么 react-native-testing-library
npm 库存在错误.
I am writing a simple test using react-native-testing-library
(my first steps with that library) in my react native expo app. But I am getting a confused error coming from somewhere inside react-native
code base itself. Either there is something wrong with my code or there is a bug with react-native-testing-library
npm library.
这是一个简单的笑话测试:
Here is simple jest test:
describe("AppTitle", () => {
it("should display applicaton title", () => {
const { getByText } = render(<AppTitle />);
expect(getByText('App Name')).toBeTruthy();
});
});
这里是简单的
组件(只是一个视图和一个文本)
And here is the simple <AppTitle />
component (just a View and a Text)
export const AppTitle = () => {
return (
<View>
<Text>App Name</Text>
</View>
);
};
但是当我运行测试时出现这个错误:
But I am getting this error when I run the test:
...../Utilities/warnOnce.js:15
const warnedKeys: {[string]: boolean} = {};
^^^^^^^^^^
SyntaxError: Missing initializer in const declaration
at ScriptTransformer.transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:471:17)
at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:513:25)
at Object.<anonymous> (node_modules/react-native/Libraries/react-native/react-native-implementation.js:14:18)
...
这是一个简单直接的模板.来自 react-native + react-native-testing-library 的任何帮助将不胜感激.
This is a simple and straight forward template. Any help from a react-native + react-native-testing-library would be appreciate.
- 反应:16.8.3
- react-native:来自
Expo 33
- jest-expo: "^33.0.2"
- react-native-testing-library": "1.7.0"
推荐答案
我解决了这个在 jest.config.js 文件中添加的 "preset": "react-native"
I resolved this added "preset": "react-native" in jest.config.js file
这篇关于语法错误:const 声明中缺少初始值设定项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!