代码之家  ›  专栏  ›  技术社区  ›  dommer

为什么用react vis chart运行“mount component”Jest测试时出现“Unexpected identifier”错误?

  •  1
  • dommer  · 技术社区  · 6 年前

    test("Create App component", () => {
      const div = document.createElement("div");
      ReactDOM.render(<App />, div);
      ReactDOM.unmountComponentAtNode(div);
    });
    

    测试基础设施是使用 create-react-app .

    App react-vis

    当我尝试运行测试时,我得到以下错误

    import _AbstractSeries from './plot/series/abstract-series';
            ^^^^^^^^^^^^^^^
    
        SyntaxError: Unexpected identifier
    
        2 | import PropTypes from "prop-types";
        3 | import { withStyles } from "@material-ui/core/styles";
        > 4 | import {
            | ^
        5 |   AreaSeries,
        6 |   Crosshair,
        7 |   CustomSVGSeries,
    
        at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
        at Object.<anonymous> (src/components/Charts/MyCustomChart.js:4:1)
    

    关于如何让这个测试工作有什么建议吗?

    0 回复  |  直到 6 年前
        1
  •  0
  •   MayTheSchwartzBeWithYou    5 年前

    经过反复寻找和拖延,我找到了解决办法。

    我发现了一条类似的失败管道: https://git.fluidware.it/milanoscaloromana/fcub/-/jobs/731

    https://git.fluidware.it/milanoscaloromana/fcub/commit/ec52c35284fd32039f256c4492e562a6180e51cc

    您需要从导入 react-vis 而不是 react-vis/es . /es 因为某种原因打包。