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

测试失败,SyntaxError:意外的令牌导出

  •  0
  • user989988  · 技术社区  · 6 年前

     FAIL  src\***.test.tsx
      ● Test suite failed to run
    
    \node_modules\office-ui-fabric-react\lib\Callout.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from './components/Callout/index';
                                                                                             ^^^^^^
    
    SyntaxError: Unexpected token export
    
      at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
    
    1 回复  |  直到 6 年前
        1
  •  3
  •   Krit    5 年前

    如果您正在使用CreateReact应用程序,您可能不想将其弹出。

    幸运的是有这个图书馆 https://github.com/timarney/react-app-rewired

    react-app-rewired 在你的CRA项目中

    package.json 包括“jest”配置

    "jest": {
      "moduleNameMapper": {
        "office-ui-fabric-react/lib/(.*)$": "office-ui-fabric-react/lib-commonjs/$1"
      },
     "transformIgnorePatterns": [
       "node_modules/(?!office-ui-fabric-react)"
     ]
    }
    

    https://github.com/OfficeDev/office-ui-fabric-react/wiki/Fabric-6-Release-Notes


    使现代化

    moduleNameMapper transformIgnorePatterns 所以没有必要使用 反应应用程序重新布线

    https://create-react-app.dev/docs/running-tests/#configuration

        2
  •  0
  •   edbentley    6 年前

    export 在ES模块中使用,但由于Jest在节点中运行,因此需要公共JS模块。请参阅上的文档 transformIgnorePatterns 关于如何使用TypeScript设置将其转换为公共JS。