morintd / prismock

A mock for PrismaClient, dedicated to unit testing.
https://www.npmjs.com/package/prismock
MIT License
203 stars 23 forks source link

feat: 🧑‍💻 delegates raise PrismaClientKnownRequestError #1105

Open paulsouche opened 1 month ago

paulsouche commented 1 month ago

This pull request covers some cases of the #1082

It is not perfect. It covers only P2025 error codes and the error messages are not the same than the prisma exceptions. As they have some legacy errors, I did not take this into consideration.

It introduces a breaking change on update as it will now raise an exception instead of returning null

That's a start. I will have a look if we can easily improve these error messages. Meanwhile, let me know what you think :pray:

thw0rted commented 2 weeks ago

@morintd could you please take a look at this? I believe it would fix a lot of tests that we currently have to skip because they expect the Prisma call to throw on missing records.

paulsouche commented 2 weeks ago

@thw0rted have you seen my workaround in #1082 ?

thw0rted commented 2 weeks ago

Yes, thanks @paulsouche -- I'm going to look at adding that, but after posting the above comment I realized that some of my findUniqueOrThrow calls do throw (just "new Error()", not the more-accurate version from this PR) while some return null instead of throwing. I haven't had a chance to investigate why this is. I probably need to figure out what's going on there first; if I'm actually hitting another bug I'll try to boil it down to a simple repro...

paulsouche commented 2 weeks ago

Feel free to fork mine it's already setup

thw0rted commented 2 weeks ago

Thanks Paul, the error wound up being a misconfigured mock, but I did run into the other issue you describe here (update should throw instead of returning null), which I've filed here as #1163, using your starter.