2017-12-07 5 views
0

create-react-app을 사용하여 React 앱을 만들었으며 구성 요소에 대한 일부 테스트를 실행하고 싶습니다. 여기 Uncaught Error : node_modules/mocha/mocha.js에서 'expect expect'모듈을 찾을 수 없습니다. 1

{ 
    "name": "timer", 
    "version": "0.1.0", 
    "private": true, 
    "dependencies": { 
    "react": "^16.2.0", 
    "react-dom": "^16.2.0", 
    "react-router": "^4.2.0", 
    "react-router-bootstrap": "^0.24.4", 
    "react-router-dom": "^4.2.2", 
    "react-scripts": "1.0.17" 
    }, 
    "scripts": { 
    "start": "react-scripts start", 
    "build": "react-scripts build", 
    "test": "karma start", 
    "eject": "react-scripts eject" 
    }, 
    "devDependencies": { 
    "expect": "^21.2.1", 
    "karma": "^1.7.1", 
    "karma-chrome-launcher": "^2.2.0", 
    "karma-mocha": "^1.3.0", 
    "karma-mocha-reporter": "^2.2.5", 
    "karma-sourcemap-loader": "^0.3.7", 
    "mocha": "^4.0.1", 
    "react-addons-test-utils": "^15.6.2" 
    } 
} 

내 테스트 파일 : 여기에
> karma start 


START: 
07 12 2017 16:18:37.676:INFO [karma]: Karma v1.7.1 server started at 
http://0.0.0.0:9876/ 
07 12 2017 16:18:37.679:INFO [launcher]: Launching browser Chrome with 
unlimited concurrency 
07 12 2017 16:18:37.690:INFO [launcher]: Starting browser Chrome 
07 12 2017 16:18:38.862:INFO [Chrome 62.0.3202 (Windows 7 0.0.0)]: Connected 
on socket 9zYM4BbuqSydz 
_toAAAA with id 71036615 
Chrome 62.0.3202 (Windows 7 0.0.0) ERROR 
Uncaught SyntaxError: Unexpected token import 
at testFiles/CountDownClock.test.js:1 

Finished in 0.154 secs/0 secs @ 16:18:39 GMT-0600 (Central Standard Time) 

SUMMARY: 
√ 0 tests completed 
Chrome 62.0.3202 (Windows 7 0.0.0) ERROR 
Uncaught Error: Cannot find module 'expect' 
at node_modules/mocha/mocha.js:1 

x Error while running the tests! Exit code: 1 

npm ERR! Test failed. See above for more details. 

내 package.json 파일입니다 : 내가 npm test을 실행할 때 다음과 같은 오류 메시지가 CountDownClock.test.js

import React from 'react'; 
import ReactDOM from 'react-dom'; 
import expect from 'expect'; 
import TestUtils from 'react-addons-test-utils'; 
import CountDownClock from 'CountDownClock'; 

describe('CountDownClock',() => { 
    it('should exist',() => { 
     expect(CountDownClock).toExist(); 
    }); 
}); 

npm 설치를 시도했지만 도움이되지 않았습니다. github에서 언급 한 몇 가지 다른 링크를 발견했지만 npm 설치를 실행하는 것이 좋습니다. 여전히 동일한 오류가 발생합니다. 어떤 도움을 주시면 고맙겠습니다. 아니면이 사실을 알기 위해 올바른 길로 나를 보내주십시오.

+0

'npm install'을 실행 했습니까? – falsarella

+0

@falsarella는 이미 내 질문에 언급 된대로 npm 설치를 실행했습니다. – iceveda06

+0

Hmmm 예상하지 못한 것은 모카였습니다. 그게 이상하지만, cd node_modules/mocha를 시도한 다음 npm install을 시도하십시오. 루트 폴더로 돌아가 npm 테스트를 다시 시도하십시오. – falsarella

답변

0

시도해보십시오. npm install expect --save. 내가 설치할 때 내 문제가 해결되었습니다.

+0

이미 다시 설치했는데 아무 것도 바뀌지 않았습니다. – iceveda06