Nest.js/TDD
-
jest unit 테스트 경로와 e2e 테스트 경로 잡아주기Nest.js/TDD 2024. 4. 16. 18:58
tsconfig.json { "compilerOptions": { .... "paths": { "@/*": ["src/*"], "test/*": ["test/*"] } } } import path를 유용하게 잡기 위해 paths 옵션을 주었을때와 루트 디렉토리 경로에서 src폴더와 별개로 테스트 파일들을 한곳에 모아서 관리하고 싶었다. 프로젝트 구조 /src /test /test/unit /test/e2e /test/jest-e2e.json Unit 테스트 파일 경로 설정하기 // 기존 package.json ... "jest": { "moduleFileExtensions": [ "js", "json", "ts" ], "rootDir": "src", "testRegex": ".*\\.spec\\.ts$"..
-
jest에서 모킹함수 'toHaveBeenCalledWith' 의 이상한점Nest.js/TDD 2024. 3. 26. 17:24
https://jestjs.io/docs/expect#tohavebeencalledwitharg1-arg2- 특정 인수를 사용하여 모의 함수가 호출되었는지 확인하는 데 사용됩니다. test('registration applies correctly to orange La Croix', () => { const beverage = new LaCroix('orange'); register(beverage); const f = jest.fn(); applyToAll(f); expect(f).toHaveBeenCalledWith(beverage); }); 특정 인수를 모의함수가 호출되었는지 테스트 하는거라고 공식문서에 나와있는데, e2e테스트를 공부하던중에 이상한 버그가 있었다. it('(GET) check co..
-
e2e 테스트를 공부 하면서 save함수의 리턴값과 toEqual로 값비교Nest.js/TDD 2024. 3. 20. 21:44
mockData = await postsRepository.save({ id: 1, author: '타입스크립트', title: '타입스크립트', content: '타입스크립트', likeCount: 0, commentCount: 0, created_at: new Date(), updated_at: new Date(), }); it('(GET) get Post /posts/:postId', async () => { const res = await request(app.getHttpServer()) .get(`/posts/${mockData.id}`) .expect(HttpStatus.OK); expect(res.body).toEqual(mockData); }); 미리 생성된 post의 id로 get요청해..
-
왜 테스트 코드를 작성 해야 하는지 알게 된 경험(typeorm bigint 이슈)Nest.js/TDD 2024. 3. 19. 18:01
e2e 테스트 공부를 하고 있었는데 - posts.entity.ts import { Column, Entity, PrimaryColumn } from 'typeorm'; @Entity() export class PostsModel { @PrimaryColumn({ type: 'bigint' }) id: number; @Column() author: string; @Column() title: string; @Column() content: string; @Column() likeCount: number; @Column() commentCount: number; } - docker-compose.yaml services: postgres: image: postgres:15 restart: always vo..
-
nestjs-test-coverage에서 제외 파일 설정Nest.js/TDD 2024. 3. 9. 20:17
- Reference https://jestjs.io/docs/configuration#coveragepathignorepatterns-arraystring Configuring Jest · Jest The Jest philosophy is to work great by default, but sometimes you just need more configuration power. jestjs.io //package.json { ... "coverageDirectory": "../coverage", "testEnvironment": "node", "coveragePathIgnorePatterns": [ "/main.ts", "/app.module.ts" ] } }
-
Nestjs에서 테스트 코드 작성시 Nest can't resolve dependencies in the RootTestModule context 에러Nest.js/TDD 2024. 1. 9. 20:57
Nest can't resolve dependencies of the ApmService (?). Please make sure that the argument dependency at index [0] is available in the RootTestModule context. Potential solutions: - If dependency is a provider, is it part of the current RootTestModule? - If dependency is exported from a separate @Module, is that module imported within RootTestModule? @Module({ imports: [ /* the Module containing ..
-