I store an instance of this class in a context type:
export type Context = {
prisma: PrismaClient;
};
For my tests, I created a mock type for the context:
export type MockContext = {
prisma: MockProxy<PrismaClient>;
};
When I want to pass this mock context to the function to test, it is unable to cast the type to a Context because of the private properties:
Conversion of type 'MockContext' to type 'Context' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Types of property 'prisma' are incompatible.
Type 'MockProxy<PrismaClient<{}, never>>' is missing the following properties from type 'PrismaClient<{}, never>': fetcher, dmmf, engineConfig, measurePerformance, and 3 more.
So for now I did a hack where I store a casted context in my mocked context:
This is a complex problem. I am a mocking a class from the Prisma library that looks like
I store an instance of this class in a context type:
For my tests, I created a mock type for the context:
When I want to pass this mock context to the function to test, it is unable to cast the type to a
Context
because of the private properties:So for now I did a hack where I store a casted context in my mocked context:
But it would be great if I could just cast the mock context directly. Thanks a lot!