无法使用WebStorm运行React组件的Jest测试

时间:2018-02-26 07:52:36

标签: reactjs webstorm jestjs

从命令行开始使用React组件,所有测试都运行得非常好。但是,当我使用WebStorm运行测试(即运行)时,我遇到了以下错误。

测试套件无法运行

({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){var _extends=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a};function _objectWithoutProperties(a,b){var c={};for(var d in a)0<=b.indexOf(d)||Object.prototype.hasOwnProperty.call(a,d)&&(c[d]=a[d]);return c}import React,{Component}from'react';import PropTypes from'prop-types';import cx from'classnames';import style from'./input.css';export default class Input extends Component{static get NORMAL(){return'normal'}static get UNDERLINE(){return'underline'}render(){const a=this.props,{className:b,inputStyle:c}=a,d=_objectWithoutProperties(a,['className','inputStyle']),e=cx([`body-small pad-05r`],{[`bdr-rad4 ${style.defInp}`]:c===Input.NORMAL,[`text-center ${style.bottomBdr}`]:c===Inpu

SyntaxError: Unexpected token import

  at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17)
  at Object.<anonymous> (src/components/input/index.jsx:3:14)
  at Object.<anonymous> (src/components/input/__tests__/input.test.js:3:14)

请帮助

1 个答案:

答案 0 :(得分:0)

对不起,延迟答复。 终于我找到了解决方案。问题是webstorm无法识别默认的.jest.config.json。我已经通过。jest.config.json作为玩笑选项参数--config .jest.config.json