0.0.102 • Published 24 days ago

@orderlycode/nest-test-tools v0.0.102

Weekly downloads
-
License
ISC
Repository
-
Last release
24 days ago

nest-test-tools

  1. 모듈을 테스트 할때는 moduleTest 를 사용한다.
describe("test", () => {
  const test = moduleTest(AppModule)
  // 여기서 바로 사용 가능
  // 내부적으로 automock을 사용한다.
  const dependencyService = context.get(DependencyService);
  // 주의 dependencyService는 모두 beforeEach후에 초기화 된다.
})
  1. 유닛 테스트 할때는 unitTest 를 사용한다.
describe("test", () => {
  // 테스트마다 다시 setup된다. (beforeEach)
  const test = moduleTest(AppModule)
  // 여기서 바로 사용 가능, constructor에 있는 것만 쓸 수 있다.
  // 내부적으로 automock을 사용한다.
  const service = context.unit;
  const dependencyService = context.get(DependencyService);
  // 주의 service, dependencyService는 모두 beforeEach후에 초기화 된다.
})
  1. mocking이 필요하다면 가져다 쓴다.
// <jestRootDir>/__mocks__/bcryptjs.ts
export * from '@orderlycode/nest-test-tools/dist/mocks/bcryptjs';
// <jestRootDir>/__mocks__/@nestjs/typeorm.ts
export * from '@orderlycode/nest-test-tools/dist/mocks/@nestjs/typeorm';

테스트 도구

jest setupAfterEnv 파일 내에 아래 내용을 추가한다.

import '@orderlycode/nest-test-tools/dist/register';

이것은 .env.test 파일을 로드하고, nock을 통해 네트워크를 차단시키며 (supertest를 위한 127.0.0.1은 허용), context를 삽입한다.

nock 네트워크 활용

네트워크 데이터 수집 (테스트가 들어있는 폴더의 _recorded폴더에 저장됨)

import {record} from '@orderlycode/nest-test-tools';

describe('test', () => {
  record('test', () => {
    // 네트워크 콜
  })
})

수집된 데이터 사용하여 테스트

import {recorded} from '@orderlycode/nest-test-tools';

describe('test', () => {
  recorded('test', () => {
    // 네트워크 콜
  })
})
0.0.102

24 days ago

0.0.101

24 days ago

0.0.100

25 days ago

0.0.11

28 days ago

0.0.10

1 month ago

0.0.9

1 month ago

0.0.8

1 month ago

0.0.7

1 month ago

0.0.6

1 month ago

0.0.5

1 month ago

0.0.4

1 month ago

0.0.3

1 month ago

0.0.2

1 month ago

0.0.1

1 month ago

0.0.0

1 month ago