npm
npm install -D jest
yarn
yarn add -D jest
-D(dev): 개발계 환경에서만 사용 가능한 devdependencies에 추가npm 버전이 5보다 낮을 경우 --save 명령어 추가 (5 이상의 버전은 save가 디폴트)npm install -D babel-jest
jest는 es5문법을 따르고 해석하기 때문에 상위버전인 es6 구문의 테스트 파일을 읽기 위해서 해당 구문을 es5로 트랜스파일 해줄수 있는 트랜스파일러 babel이 필요하다.npm install -D ts-jest
react
npm install -D react-jest
vue
npm install -D vue-jest
moduleFileExtensions: ['js', 'ts', 'json', 'vue']
transform: {
'^.+\\.js$': '<rootDir>/node_modules/babel-jest'
...
⭐️ 테스트하고자 하는 파일 확장자에 대한 설정을 추가로 할 수 있다
'.*\\.(vue)$': '<rootDir>/node_modules/vue-jest'
}
moduleNameMapper: {
'^@client/(.*)$': '<rootDir>/src/$1',
'^@client/common/(.*)$': '<rootDir>/src/common/$1',
}


"scripts": {
"test": "jest"
}
⭐️ coverage를 통한 품질 지표 확인
yarn test --coverage
또는 package.json 추가
"scripts": {
"test": "jest --coverage"
}
