describe - 그룹 테스트 단위
beforeEach - 테스트가 진행되기전 사전에 진행되는 코드
it - 최소 테스트 단위
import { AppController } from './app.controller';
import { AppService } from './app.service';
describe('AppController', () => {
let appService: AppService; //의존성 주입
let appController: AppController; //의존성 주입
beforeEach(() => { //테스트 단위인 it가 진행되기전 사전에 진행되는 코드
appService = new AppService();
appController = new AppController(appService);
});
describe('getHello', () => {
it('이 테스트의 검증 결과는 Hello World를 리턴해야함!!', () => {
const result = appController.getHello();
expect(result).toBe('Hello World!');
});
});
});
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
describe('AppController', () => {
let appController: AppController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
appController = app.get<AppController>(AppController);
});
describe('getHello', () => {
it('이 테스트의 검증 결과는 Hello World를 리턴해야함!!', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});