1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

jest、prismaを使ったテストで Jest did not exit one second after the test run has completed. が出たときの解決法

Posted at
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();
  });
});

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?