【问题标题】:React Native Jest Syntax Error: Unterminated Regular ExpressionReact Native Jest 语法错误:未终止的正则表达式
【发布时间】:2019-05-13 09:05:22
【问题描述】:

在为我正在编写的 Todo 演示运行简单测试时,我遇到了这个奇怪的语法错误。我已经在同一个文件中添加了代码和测试,这样你就可以看到发生了什么。

任何帮助将不胜感激。

import { Text } from 'react-native';
import React from 'react';
import { shallow } from 'enzyme';

const TodoItem = () => {
  return(
    <Text>{Hello}</Text>
  );
};

export default TodoItem;

describe('<TodoItem', () => {
  it('should update uncompleted task to complete when pressed', () => {
    const wrapper = shallow(<TodoItem />)
  });
});

测试结果

运行:jest

 FAIL  __tests__/components/TodoItem.spec.tsx
  ● Test suite failed to run

    SyntaxError: /Users/jonesagyemang/Projects/side/Todoist/__tests__/components/TodoItem.spec.tsx: Unterminated regular expression (7:19)

       5 | const TodoItem = () => {
       6 |   return(
    >  7 |     <Text>{Hello}</Text>
         |                    ^
       8 |   );
       9 | };
      10 |

      at Object.raise (../../../../../usr/local/lib/node_modules/jest/node_modules/@babel/parser/lib/index.js:6322:17)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.2s
Ran all test suites related to changed files.

Watch Usage: Press w to show more.

【问题讨论】:

    标签: reactjs react-native jestjs babel-jest


    【解决方案1】:

    我假设它是您想用Text 组件显示的文本。尝试删除 Hello 的 {},因为它不是代码中的变量或函数。

    const TodoItem = () => {
      return(
        <Text>Hello</Text>
      );
    };
    

    【讨论】:

    • 我试过了,但是不行。事实上,最初花括号并不在它周围。我只是把它放在那里只是为了试验。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-03
    • 2011-11-26
    • 1970-01-01
    • 1970-01-01
    • 2015-03-27
    • 1970-01-01
    相关资源
    最近更新 更多