1.0.5 • Published 10 months ago

@orderlycode/nest-test-tools v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months 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';

테스트 도구

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', () => {
    // 네트워크 콜
  })
})
1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago

0.0.115

11 months ago

0.0.114

11 months ago

0.0.113

11 months ago

1.0.5

10 months ago

0.0.112

11 months ago

1.0.4

10 months ago

1.0.3

10 months ago

0.0.111

2 years ago

0.0.110

2 years ago

0.0.106

2 years ago

0.0.105

2 years ago

0.0.104

2 years ago

0.0.103

2 years ago

0.0.12

2 years ago

0.0.109

2 years ago

0.0.108

2 years ago

0.0.107

2 years ago

0.1.0

2 years ago

0.1.1

2 years ago

0.0.102

2 years ago

0.0.101

2 years ago

0.0.100

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago