feat: add nestjs app (#172)
This commit is contained in:
1 parent
7f2ab7f192
commit
9440d04261
16 files changed
+2181
-181
No files matched your search
@@ -0,0 +1,39 @@
|
||||
/* 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user