Files
Homarr/apps/nestjs/src/app.controller.spec.ts
2024-03-03 21:07:27 +01:00

40 lines
1.1 KiB
TypeScript

/* eslint-disable @typescript-eslint/unbound-method */
import type { TestingModule } from "@nestjs/testing";
import { Test } from "@nestjs/testing";
import { beforeEach, describe, expect, it, vitest } from "vitest";
import { AppController } from "./app.controller";
import { AppService } from "./app.service";
import { DatabaseService } from "./db/database.service";
describe("AppController", () => {
let appController: AppController;
let appService: AppService;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService, DatabaseService],
}).compile();
appController = app.get<AppController>(AppController);
appService = app.get<AppService>(AppService);
});
describe("root", () => {
it('should return "Hello World!"', async () => {
// arrange
vitest
.spyOn(appService, "getHello")
.mockReturnValueOnce(Promise.resolve("ABC"));
// act
const a = await appController.getHello();
// assert
expect(a).toBe("ABC");
expect(appService.getHello).toHaveBeenCalledTimes(1);
});
});
});