运行React / Redux / Karma / Jasmine / Webpack

时间:2017-04-24 22:46:14

标签: reactjs webpack karma-jasmine

我在运行Karma / Webpack时遇到基本的加载错误。

我的主应用程序/网站使用Webpack捆绑导出的React模块,这非常好用。

当我运行 npm test 以启动Webpack和Karma时,我收到此错误

    ERROR in ./app/react/components/bots/botShowContainer.js
    Module build failed: SyntaxError: D:/development/poc9-unittests/app/react/components/bots/botShowContainer.js: Unexpected token (11:8)


   9 | const BotShowUI = ({ bot,  onClick  }) => {
  10 |     return(
> 11 |         <div id={bot.id}  onClick={onClick}>
     |         ^
  12 |             {bot.id} : {bot.text}
  13 |         </div>
  14 |     )

我已经用这个小项目创建了一个GitHub仓库 https://github.com/bikerboyroy/poc.git

npm install

npm start,运行localhost:8080

npm测试,运行业力测试

因为你会看到业力测试失败

导入/导出测试失败但是抱怨反应语法。我很困惑!

注意: Web应用程序以角度1.4启动,然后桥接到React。  我只对测试React方面的东西感兴趣,而不是角度bootstrap / startup

1 个答案:

答案 0 :(得分:2)

将你的babelrc更改为包含babel-preset-react,它应该可以正常工作。您现在可以看到它正在提供错误。因为它不知道如何转换jsx语法。

{
  "presets": ["es2015", "react"]
}

顺便说一下,你不需要在babpack的加载器部分的webpack中指定查询选项,因为你的项目中已经有了babelrc。

您的装载机可以是这样的: -

  {
    test: /\.js$/,
    loader: "babel",
    exclude: [/node_modules/,  "app/**/*.spec.js"]
  },