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 { Test, TestingModule } from "@nestjs/testing";
|
||||||
import { AppController } from "@/app.controller";
|
import { AppController } from "@/app.controller";
|
||||||
import { AppService } from "@/app.service";
|
import { AppService } from "@/app.service";
|
||||||
|
import { SkillsService } from "@/skills/skills.service";
|
||||||
|
import { SkillDto } from "@/skills/skills.types";
|
||||||
|
|
||||||
describe('AppController', () => {
|
describe("AppController", () => {
|
||||||
let appController: 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', () => {
|
appController = app.get<AppController>(AppController);
|
||||||
it('should return "Hello World!"', () => {
|
appService = app.get<AppService>(AppService);
|
||||||
expect(appController.sayHello()).toBe('Hello World!');
|
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