test.ts
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
describe("sample", () => {
test("sample", async () => {
const user = await prisma.user.findFirst();
expect(user).toBeTruthy();
});
});
これを実行すると
Jest did not exit one second after the test run has completed.
が出た。
解決法
await prisma.$disconnect();
を追加する
test.ts
import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();
describe("sample", () => {
// 追加
afterAll(async () => {
await prisma.$disconnect();
});
test("sample", async () => {
const user = await prisma.user.findFirst();
expect(user).toBeTruthy();
});
});