REDUX测试意外的令牌错误



我正在遇到一个test_helper文件的问题,该文件用来完全正常工作。这是我一段时间后回到的一个项目。错误和文件与软件包一起。

错误

SyntaxError: /Users/mikewalters/Projects/video-
frontend/test/test_helper.js: Unexpected token (20:4)
18 | function renderComponent(ComponentClass, props = {}, state = {}) {
19 |   const componentInstance =  TestUtils.renderIntoDocument(
> 20 |     <Provider store={createStore(reducers, state)}>
   |     ^
21 |       <ComponentClass {...props} />
22 |     </Provider>
23 |   );

test_helperjs

import _$ from 'jquery';
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import jsdom from 'jsdom';
import chai, { expect } from 'chai';
import chaiJquery from 'chai-jquery';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import reducers from '../src/reducers';
global.document = jsdom.jsdom('<!doctype html><html><body></body></html>');
global.window = global.document.defaultView;
const $ = _$(window);
chaiJquery(chai, chai.util, $);
function renderComponent(ComponentClass, props = {}, state = {}) {
  const componentInstance =  TestUtils.renderIntoDocument(
    <Provider store={createStore(reducers, state)}>
      <ComponentClass {...props} />
    </Provider>
  );
  return $(ReactDOM.findDOMNode(componentInstance));
}
$.fn.simulate = function(eventName, value) {
  if (value) {
    this.val(value);
  }
  TestUtils.Simulate[eventName](this[0]);
};
export {renderComponent, expect};
import _$ from 'jquery';
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import jsdom from 'jsdom';
import chai, { expect } from 'chai';
import chaiJquery from 'chai-jquery';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import reducers from '../src/reducers';
global.document = jsdom.jsdom('<!doctype html><html><body></body></html>');
global.window = global.document.defaultView;
const $ = _$(window);
chaiJquery(chai, chai.util, $);
function renderComponent(ComponentClass, props = {}, state = {}) {
  const componentInstance =  TestUtils.renderIntoDocument(
    <Provider store={createStore(reducers, state)}>
      <ComponentClass {...props} />
    </Provider>
  );
  return $(ReactDOM.findDOMNode(componentInstance));
}
$.fn.simulate = function(eventName, value) {
  if (value) {
    this.val(value);
  }
  TestUtils.Simulate[eventName](this[0]);
};
export {renderComponent, expect};

package.json

"scripts": {
    "start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
    "test": "mocha -r mock-local-storage --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
    "test:watch": "npm run test -- --watch",
    "coverage": "babel-node ./node_modules/.bin/isparta cover --include 'src/**/*.js*' _mocha"
  },

这些测试以前有效,甚至没有进行测试的事实使我相信更改的编译器或软件包是一种东西。但是我无法在网上找到有关这个问题的任何东西。

我缺少.babelrc文件。最终添加了这个,它开始工作

{
 "presets": [ "react","es2015","es2016","stage-0" ]
}

相关内容

  • 没有找到相关文章

最新更新