0.1.1 • Published 12 months ago
@orderlycode/nest-test-tools v0.1.1
nest-test-tools
- 모듈을 테스트 할때는 moduleTest 를 사용한다.
describe("test", () => {
const test = moduleTest(AppModule)
// 여기서 바로 사용 가능
// 내부적으로 automock을 사용한다.
const dependencyService = context.get(DependencyService);
// 주의 dependencyService는 모두 beforeEach후에 초기화 된다.
})
- 유닛 테스트 할때는 unitTest 를 사용한다.
describe("test", () => {
// 테스트마다 다시 setup된다. (beforeEach)
const test = moduleTest(AppModule)
// 여기서 바로 사용 가능, constructor에 있는 것만 쓸 수 있다.
// 내부적으로 automock을 사용한다.
const service = context.unit;
const dependencyService = context.get(DependencyService);
// 주의 service, dependencyService는 모두 beforeEach후에 초기화 된다.
})
- 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.111
1 year ago
0.0.110
1 year ago
0.0.106
1 year ago
0.0.105
1 year ago
0.0.104
1 year ago
0.0.103
1 year ago
0.0.12
12 months ago
0.0.109
1 year ago
0.0.108
1 year ago
0.0.107
1 year ago
0.1.0
12 months ago
0.1.1
12 months ago
0.0.102
1 year ago
0.0.101
1 year ago
0.0.100
1 year ago
0.0.11
1 year ago
0.0.10
1 year ago
0.0.9
1 year ago
0.0.8
1 year ago
0.0.7
1 year ago
0.0.6
1 year ago
0.0.5
1 year ago
0.0.4
1 year ago
0.0.3
1 year ago
0.0.2
1 year ago
0.0.1
1 year ago
0.0.0
1 year ago