不能 运行 摩卡测试与 create-react-app

Can't run mocha tests with create-react-app

我正在尝试 运行 使用 mocha 测试我的 create-react-application 生成的 react/redux application.But 我收到这个错误:

import leaveReducer from '../reducers/leave.reducer.js'                                                          

^^^^^^                                                                                                           


SyntaxError: Unexpected token import                                                                             
   at createScript (vm.js:80:10)                                                                                
   at Object.runInThisContext (vm.js:152:10)                                                                    
   at Module._compile (module.js:624:28)                                                                        
   at Object.Module._extensions..js (module.js:671:10)                                                          
   at Module.load (module.js:573:32)                                                                            
   at tryModuleLoad (module.js:513:12)                                                                          
   at Function.Module._load (module.js:505:3)                                                                   
   at Module.require (module.js:604:17)                                                                         
   at require (internal/module.js:11:18) 

我无法在我的 test.I 中编写 ES6 语法,我想我缺少对应用程序进行的某种配置。 谢谢。

您需要将您的 package.json 文件或 .babelrc 修改为

scripts: {
  "test": "./node_modules/.bin/mocha --require babel-register 'PATH TO YOUR TEST DIR OR FILE' "
  }