由于意外的令牌,React Test Suite失败

时间:2018-12-10 09:18:36

标签: reactjs jestjs enzyme babel-jest

我的代码有问题。我正在使用JEST&Enzyme对我的项目进行测试。

ChildComponent:

// Shortened for simplicity
Object.assign(ReactTableDefaults.column, {
    style: {"textAlign": "left"},
    headerStyle: {
      "fontWeight": "600", 
      "fontSize": "0.9em",
      "backgroundColor": "#DDE7ED",
      "color": "#1D3557",
      "borderColor": "#1D3557",
      "textAlign": "left"
    }
});

ParentComponent:

// Shortened for simplicity
render() {
let ChildComponent;
if (!this.state.submittedSearch) {
  ChildComponent = (
    <div style={{ textAlign: "center" }}>
      <hr />
      <h3>Please ensure that you fill up all the fields.</h3>
    </div>
  );
} else {
  ChildComponent = (
    <div>
      <Row>
        <ChildComponent
          {...props} />
      </Row>
    </div>
  );

这是我遇到的错误:

//Shortened for simplicity

●测试套件无法运行

E:\cv_UserTemp\*****\node_modules\react-table\react-table.css:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){.ReactTable{position:relative;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;border:1px solid rgba(0,0,0,0.1);}.ReactTable *{box-sizing:border-box}.ReactTable .rt-table{-webkit-box-flex:1;-ms-flex:auto 1;flex:auto 1;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;-webkit-box-align:stretch;-ms-flex-align:stretch;align-items:stretch;width:100%;border-collapse:collapse;overflow:auto}.ReactTable .rt-thead{-webkit-box-flex:1;-ms-flex:1 0 auto;flex:1 0 auto;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;-webkit-user-select:none;-moz-

SyntaxError: Unexpected token .

  17 |       "fontWeight": "600",
  18 |       "fontSize": "0.9em",
> 19 |       "backgroundColor": "#DDE7ED",
  20 |       "color": "#1D3557",
  21 |       "borderColor": "#1D3557",
  22 |       "textAlign": "left"

  at ScriptTransformer._transformAndBuildScript (I:/*****/node_modules/jest-runtime/build/script_transformer.js:316:17)

我不确定导致此错误的原因。起初,我怀疑这与我的webpack.config.js.babelrc有关。但是在修改我的代码之后,我仍然不确定发生了什么。以下是我的.babelrc的样子:

//.babelrc
{
  "presets": [
    "babel-preset-flow",
    "babel-preset-latest",
    "babel-preset-env",
    "babel-preset-stage-2",
    "react",
    [
      "env",
      {
        "modules": false
      }
    ]
  ],
  "plugins": [
    "react-hot-loader/babel"
  ]
}

我正在使用以下内容:

  • 反应v15.6.2
  • ReactDom v15.6.2
  • babel-polyfill v6.23.0
  • babel-jest v23.0.1
  • babel-preset-env v1.4.0

谢谢您的帮助

0 个答案:

没有答案