【问题标题】:React, semantic-ui-react. Test suite failed to run: SyntaxError: Unexpected token import反应,语义用户界面反应。测试套件无法运行:SyntaxError: Unexpected token import
【发布时间】:2018-02-26 23:44:02
【问题描述】:

重现步骤

新的“create-react-app”; yarn add semantic-ui-react; 只需以下代码的新组件:

import React, { PureComponent } from "react";
import Dropdown from "semantic-ui-react/dist/es/modules/Dropdown/Dropdown";

class NavbarRightMenu extends PureComponent {
  render() {
    <Dropdown item trigger={myTrigger}>
      <Dropdown.Menu>Something! Booom!</Dropdown.Menu>
    </Dropdown>;
  }
}

预期结果

yarn test一切正常!

实际结果

现在我得到了这个:

src\index.test.js
  ● Test suite failed to run

    C:\Project\node_modules\semantic-ui-react\dist\es\modules\Dropdown\Dropdown.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import _defineProperty from 'babel-runtime/helpers/defineProperty';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token import

      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
      at Object.<anonymous> (src/components/common/navbar_components/NavbarRightMenu.js:3:17)
      at Object.<anonymous> (src/components/common/NavbarCommon.js:6:24)

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

Watch Usage: Press w to show more.

版本

0.76.0

测试用例

https://codesandbox.io/s/736j2w2ol6

我不知道如何在代码沙盒上进行测试。

【问题讨论】:

    标签: javascript reactjs semantic-ui jestjs create-react-app


    【解决方案1】:

    将您的导入更改为:

    import { Dropdown } from 'semantic-ui-react'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-21
      • 1970-01-01
      • 2020-08-15
      • 2018-03-08
      • 2019-10-28
      • 2016-10-20
      • 1970-01-01
      • 2021-11-03
      相关资源
      最近更新 更多