2017-08-30 76 views
0

我遇到了test_helper文件的問題,該文件用於非常好地工作。這是我一段時間後回來的一個項目。錯誤和文件與package.json一起,因爲我懷疑它可能是編譯器引起的問題。Redux測試意外令牌錯誤

的錯誤

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" 
    }, 

這些測試之前工作過,事實上,它不是讓,甚至在測試貸出我相信這是編譯器或包改變了。但我一直無法在網上找到關於此問題的任何信息。

回答

0

我錯過了一個.babelrc文件。結束加入並開始工作

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