반응형
Jest
Jest는 JavaScript 코드가 제대로 동작하는지 확인하는 테스트 케이스를 만드는 테스팅 프레임워크다. 여러가지 상황들을 설정하고, 그 상황에 따라 적절한 결과가 나오는지 자동으로 테스트할 수 있기에, 프로젝트 규모가 클 때 유용하다.
설치
# npm
npm install --save-dev jest
# yarn
yarn add --dev jest
기본 사용법
1. 함수 export
// sum.js
function sum(a, b) {
return a + b;
}
module.exports = sum;
2. 함수 불러오기
// sum.test.js
const sum = require('./sum');
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
3. package.json 내 scripts에 테스트 명령어 작성
{
"scripts": {
"test": "jest",
"test:1": "jest 1-example/",
"test:2": "jest 2-example/",
"test:watch": "jest --watch",
"test:circleci": "jest --json --outputFile=.circleci/results.json",
...
}
}
4. test 명령어 실행
# yarn
yarn test
# npm
npm run test
공식 문서
Jest
By ensuring your tests have unique global state, Jest can reliably run tests in parallel. To make things quick, Jest runs previously failed tests first and re-organizes runs based on how long test files take.
jestjs.io
반응형
'웹_프론트엔드 > 로드맵 챌린지' 카테고리의 다른 글
테스트 프레임워크 - Cypress (0) | 2022.03.15 |
---|---|
테스트 프레임워크 - react-testing-library (0) | 2022.03.14 |
CSS 프레임워크 - Bulma (0) | 2022.03.10 |
CSS 프레임워크 - Materialize CSS (0) | 2022.03.08 |
CSS 프레임워크 - Bootstrap (부트스트랩) (0) | 2022.03.07 |