getting a typescript error when trying to use drizzle.mock()

I'm trying to mock my drizzle driver for some unit tests. I'm using drizzle.mock(). When I pass it into the function that takes it, I get the following error:
Argument of type
NodePgDatabase<Record<string, never>> & {
$client: "$client is not available on drizzle.mock()";
}
is not assignable to parameter of type
NodePgDatabase<typeof import("/home/nico/src/idem/packages/backend/src/db/schema")> & {
$client: Pool;
}
Type
NodePgDatabase<Record<string, never>> & {
$client: "$client is not available on drizzle.mock()";
}
is not assignable to type
NodePgDatabase<typeof import("/home/nico/src/idem/packages/backend/src/db/schema")>
Argument of type
NodePgDatabase<Record<string, never>> & {
$client: "$client is not available on drizzle.mock()";
}
is not assignable to parameter of type
NodePgDatabase<typeof import("/home/nico/src/idem/packages/backend/src/db/schema")> & {
$client: Pool;
}
Type
NodePgDatabase<Record<string, never>> & {
$client: "$client is not available on drizzle.mock()";
}
is not assignable to type
NodePgDatabase<typeof import("/home/nico/src/idem/packages/backend/src/db/schema")>
I tried to modify the property, to have a null pool, but I get another error telling me that type Pool isn't compatible with the prop's type. how do I mock the driver? I've been at it for the past couple of days and am super confused 😖
4 Replies
JustWayne
JustWayne•3mo ago
I have been using import { type NeonHttpDatabase as DbClient } from "drizzle-orm/neon-http"; in my project. Other work that I've done figuring out how to use the generic types is mentioned here - https://discord.com/channels/1043890932593987624/1392559056572645388/1393275780330426450
YonoZekenZoid
YonoZekenZoidOP•3mo ago
thanks, I'll check that out. I am, however, looking for a way to completely mock out the DbClient. not sure how this would achieve that
JustWayne
JustWayne•3mo ago
If you use Record<string, unknown> it should work, that's what they're doing in all the mock functions - https://github.com/drizzle-team/drizzle-orm/blob/ac1dcd9d1c4b8f171479af4a5dd731db1e164f58/drizzle-orm/src/node-postgres/driver.ts#L145 e.g. NodePgDatabase<Record<string, unknown>>
YonoZekenZoid
YonoZekenZoidOP•3mo ago
thx I'll give it a try

Did you find this page helpful?