[Snow-ball]server/NestJS
[NestJS] 유닛 테스트(Unit Testing) 간단한 사용방법 코드 정리
Snow-ball
2023. 2. 1. 15:38
반응형
유닛테스트 테스트 구조
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
describe('UsersExistsNicknameUseCase', () => {
let service: UsersExistsNicknameUseCase;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
UsersExistsNicknameUseCase,
PrismaService,
{
provide: 'EXISTS_NICKNAME',
useClass: UsersExistsNicknameRepository,
},
],
}).compile();
service = module.get<UsersExistsNicknameUseCase>(
UsersExistsNicknameUseCase,
);
});
let dto: UsersExistsNicknameInputDto;
describe('exists nickname', () => {
it('failed should nickname check', async () => {
dto = {
nickname: 'a',
};
const {
response: { nickname },
} = await service.existsNickname(dto);
expect(nickname).toStrictEqual(false);
});
it('success should nickname check', async () => {
dto = {
nickname: 'nickaaa',
};
const {
response: { nickname },
} = await service.existsNickname(dto);
expect(nickname).toStrictEqual(true);
});
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
|
cs |
반응형