Coner Murphy
Coner Murphy
DTDrizzle Team
Created by Coner Murphy on 11/29/2024 in #help
How to spy on Drizzle in Vitest to throw an error
Hi, I want to spy on a drizzle call in my vitest tests and use that spy to throw an error so I can test my error handling around the Drizzle call in my code should it fail. In the past I've done things like the below in Prisma but haven't had any luck replicating it with Drizzle yet and wanted to know if anyone else has managed to do something similiar. Ideally I want to just spy on a specific call update to a table (users) like in the example below.
jest.spyOn(prisma.users, 'update').mockRejectedValueOnce(
new Prisma.PrismaClientKnownRequestError('Operations timed out', {
code: 'P1008',
})
);
jest.spyOn(prisma.users, 'update').mockRejectedValueOnce(
new Prisma.PrismaClientKnownRequestError('Operations timed out', {
code: 'P1008',
})
);
Any help would be greatly appreciated.
1 replies