it('something', () => {
// 테스트 케이스 내용
});
describe('Math operations', () => {
it('should add two numbers', () => {
// 테스트 내용
});
it('should subtract two numbers', () => {
// 테스트 내용
});
});
it('should add two numbers correctly', () => {
expect(sum(1, 2)).toBe(3);
});
it('should check if two arrays are equal', () => {
expect([1, 2, 3]).toEqual([1, 2, 3]);
});
it('should check if array contains a specific element', () => {
expect([1, 2, 3]).toContain(2);
});
yarn test:cov"test:cov" : "jest --coverage"가 추가되어야 한다.yarn test : 일반적으로 프로젝트의 테스트 스크립트를 실행하는 명령어. package.json 파일의 scripts 섹션에 정의된 test 스크립트를 실행한다. 프로젝트 설정에 따라 다양한 테스트 프레임워크나 런너 사용가능하다. (아래의 사진에서는 test가 jest로 되어있기 때문에 yarn test는 yarn jest와 동일함) --watch 플래그: 파일 변경사항 감지하여 테스트를 자동으로 다시 실행 가능하다.
yarn test:e2e : e2e 테스트를 실행한다.yarn test:cov : 코드 커버리지를 측정하고 보고한다. yarn jest : 직접적으로 Jest를 실행한다. jest.config.js 파일에 설정된 구성이 사용된다. 
src/app.controller.spec.ts : 단위테스트(TDD)를 위한 파일yarn test or yarn jesttest/app.e2e-spec.ts : e2e테스트(BDD)를 위한 파일yarn test:e2etest/jest-e2e.json : Jest e2e테스트 설정파일jest-e2e.json
{ "moduleFileExtensions": ["js", "json", "ts"], "rootDir": ".", "testEnvironment": "node", "testRegex": ".e2e-spec.ts$", "transform": { "^.+\\.(t|j)s$": "ts-jest" } }
- moduleFileExtensions: 테스트 파일에서 모듈로 사용할 수 있는 확장자들의 배열을 정의
- rootDir: Jest가 테스트 파일 및 구성 파일을 찾기 시작하는 기본 디렉토리를 지정
- testEnvironment: 테스트가 실행될 환경을 지정 [ex] node, browser
- testRegex: Jest가 실행할 테스트 파일을 선택하는 데 사용되는 정규식을 지정 (여기서는 .e2e-spec.ts로 끝나는 파일들을 선택하도록 설정)
- transform: Jest가 특정 유형의 파일을 변환하는 방법을 지정