SyntaxError:const声明中缺少初始化程序 [英] SyntaxError: Missing initializer in const declaration

查看:744
本文介绍了SyntaxError:const声明中缺少初始化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在React Native Expoo应用程序中使用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();
  });
});

这是简单的<AppTitle />组件(只是一个视图和一个文本)

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.

  1. 反应:16.8.3
  2. 本机:来自Expo 33
  3. 的分叉
  4. jest-expo:"^ 33.0.2"
  5. react-native-testing-library":"1.7.0"
  1. react: 16.8.3
  2. react-native: fork from Expo 33
  3. jest-expo: "^33.0.2"
  4. react-native-testing-library": "1.7.0"

推荐答案

我解决了在jest.config.js文件中添加的预设":"react-native"

I resolved this added "preset": "react-native" in jest.config.js file

这篇关于SyntaxError:const声明中缺少初始化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆