Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prisma Client Error won't be handled properly #79

Open
aokht opened this issue Mar 14, 2023 · 1 comment
Open

Prisma Client Error won't be handled properly #79

aokht opened this issue Mar 14, 2023 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@aokht
Copy link

aokht commented Mar 14, 2023

Thank you for the great library.

When I tried to add a following test into the examples/example-prj/src/service, I found a suspicious behavior.

import { Prisma, PrismaClient } from "@prisma/client";

describe.each([
  ["Original PrismaClient", new PrismaClient()],
  ["jestPrisma.client", jestPrisma.client],
])("%s", (_, prisma) => {
  test("handles prisma error properly", async () => {
    try {
      await prisma.user.update({
        data: { name: "" },
        where: { id: "record_not_found" },
      });
    } catch (e) {
      expect(e).toBeInstanceOf(Prisma.PrismaClientKnownRequestError);
    }
  });
});
npm run test:ci src/service/prismaError.test.ts

> example-prj@1.4.0 test:ci
> DATABASE_URL="file:./test.db" jest "src/service/prismaError.test.ts"

 FAIL  src/service/prismaError.test.ts
  Original PrismaClient
    ✓ handles prisma error properly (19 ms)
  jestPrisma.client
    ✕ handles prisma error properly (144 ms)

  ● jestPrisma.client › handles prisma error properly

    expect(received).toBeInstanceOf(expected)

    Expected constructor: PrismaClientKnownRequestError
    Received constructor: PrismaClientKnownRequestError

      12 |       });
      13 |     } catch (e) {
    > 14 |       expect(e).toBeInstanceOf(Prisma.PrismaClientKnownRequestError);
         |                 ^
      15 |     }
      16 |   });
      17 | });

      at Object.<anonymous> (src/service/prismaError.test.ts:14:17)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        3.502 s

It seems that the prisma error thrown via jestPrisma.client isn't recognized as an instanceof PrismaClientKnownRequestError properly (even though it shows a same name "PrismaClientKnownRequestError")

And this prevents us from handling prisma errors by the way the official document provides.

Do you have any idea on this?
Thanks!

@dantetwc
Copy link

dantetwc commented Jan 9, 2024

Same here and it breaks the test cases

@Quramy Quramy added the help wanted Extra attention is needed label Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants