Added tests for SkillsService
This commit is contained in:
parent
92c3d833f9
commit
d5132520cb
1 changed files with 41 additions and 13 deletions
|
|
@ -1,22 +1,50 @@
|
|||
import { Test, TestingModule } from "@nestjs/testing";
|
||||
import { AppController } from "@/app.controller";
|
||||
import { AppService } from "@/app.service";
|
||||
import { SkillsService } from "@/skills/skills.service";
|
||||
import { SkillDto } from "@/skills/skills.types";
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
describe("AppController", () => {
|
||||
let appController: AppController;
|
||||
let appService: AppService;
|
||||
let skillsService: SkillsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService, SkillsService],
|
||||
}).compile();
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.sayHello()).toBe('Hello World!');
|
||||
appController = app.get<AppController>(AppController);
|
||||
appService = app.get<AppService>(AppService);
|
||||
skillsService = app.get<SkillsService>(SkillsService);
|
||||
});
|
||||
|
||||
describe("root", () => {
|
||||
it("Should call AppService", () => {
|
||||
jest.spyOn(appService, "sayHello").mockImplementation(() => "Hello World!")
|
||||
appController.sayHello();
|
||||
expect(appService.sayHello).toBeCalled();
|
||||
});
|
||||
|
||||
it("should return \"Hello World!\"", () => {
|
||||
expect(appController.sayHello()).toBe("Hello World!");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getSkills", () => {
|
||||
it("Should return an Array of SkillDtos", () => {
|
||||
const result: SkillDto[] = SkillDto.asDto([{
|
||||
name: "skillName",
|
||||
category: "skillCategory",
|
||||
description: "skillDescription"
|
||||
}]);
|
||||
|
||||
jest.spyOn(skillsService, "getMany").mockImplementation(() => result)
|
||||
expect(appController.getSkills()).toBe(result);
|
||||
expect(skillsService.getMany).toBeCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue