로그가 잘뜨는지 확인 하는 테스트코드 작성
컨트롤러.ts
@Controller()
export class LoggerTestController {
readonly logger = new Logger('LoggerTest.contoller');
test(){
this.logger.log("이게 나와야된다");
return { value:"리턴은 이거"};
}
}
컨트롤러.spec.ts
describe('컨트롤러', () => {
let controller: LoggerTestController;
let service: LoggerTestService;
beforeAll(async () => {
const MockModule: TestingModule = await Test.createTestingModule({
controllers: [LoggerTestController],
providers: [
{
provide: LoggerTestService,
useClass: MockLoggerTestService,
},
],
}).compile();
controller = MockModule.get<LoggerTestController>(LoggerTestController);
service = MockModule.get<LoggerTestService>(LoggerTestService);
});
it('post성공했을 때 로그 띄워줘야함', async () => {
const spylog = jest.spyOn(controller.logger, 'log').mockReturnValue();
await controller.test();
expect(spylog).toHaveBeenCalledWith('OO님이 상품을 등록을 하셨습니다');
});
});
'TIL,WIL(일간,주간 회고)' 카테고리의 다른 글
TIL interface 교차타입 (0) | 2023.05.30 |
---|---|
[vscode]에서 파일 변화 인식 못할 때 (0) | 2023.05.12 |
dotenv사용할때 알게된점 (0) | 2023.04.17 |
cannot find type definition file for 'morgan'. the file is in the program because:\n entry point for implicit type library 'morgan' (0) | 2023.04.17 |
sourcetree(소스트리) 클론시 올바른 원본 경로 url이 아니라고 뜰 때 (0) | 2023.04.17 |