2017-04-09 4 views
1

효소/모카로 반응 성분을 테스트하려고하는데 설정 방법에 대해 약간 혼란 스럽습니다. 내가 오류 여기베벨을 사용하여 모카로 반응 성분을 테스트하십시오

env NODE_ENV=test mocha --compilers js:babel-register --require babel-polyfill --reporter spec --timeout 5000 --recursive 

그리고있다 :

SyntaxError: /my_app/public/js/components/polls/index.js: Unexpected token (47:10) 
    45 | eachPoll(poll, i) { 
    46 |  return(
> 47 |   <Link to={"/poll/" + poll._id} key={poll._id}> 
    |   ^
    48 |    <div className="btn btn-info btn-block"> 
    49 |    {poll.name} 
    50 |    </div> 

문제 여기

내가 테스트를 시작하기 위해 실행 명령 테스트 여기

import React from 'react'; 
import { expect } from 'chai'; 
import { shallow, mount, render } from 'enzyme'; 
import Index from '../../public/js/components/polls/index' 

describe("INDEX", function() { 
    it("contains a div", function() { 
    expect(shallow(<Index />).contains(<div id="index">)).to.equal(true); 
    }); 

}); 

입니다 JSX와 같이 보이지만,이 구성 요소를 webpack으로 잘 만들 수 있습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

+0

파일 확장자'이다 .js' 또는'.jsx'? –

답변

3

당신은 바벨을 통해 테스트를 실행하는 바벨 등록 옵션 모카를 실행해야합니다

--compilers js:node_modules/babel-register 

당신이 당신의 루트 디렉토리에 .babelrc 파일이 있는지 확인합니다. 적어도 react 프리셋을 포함해야합니다. .babelrc에 대한

예 :

{ 
    "presets": [ 
     "es2015", 
     "react" 
    ] 
} 
+0

감사! 나는이 명령을'env NODE_ENV = test mocha --compilers js : node_modules/babel-register -require babel-polyfill --reporter spec --timeout 5000 --rerecive' 테스트로 바꾸었고 같은 에러가났다. – stoebelj

+0

' .babelrc' 파일? –

+0

예'{ "사전 설정": [ "es2015" ] } ' – stoebelj