I'm trying to create unit tests in NestJS with Pri...
# orm-help
s
I'm trying to create unit tests in NestJS with Prisma and found some examples and with the documentation on Prisma. Now trying to get it all working I'm running into some issues. context.ts
Copy code
import { PrismaClient } from '.prisma/client';
import { mockDeep } from 'jest-mock-extended';
import { DeepMockProxy } from 'jest-mock-extended/lib/cjs/Mock';

export type Context = {
  prisma: PrismaClient;
};

export type MockContext = {
  prisma: DeepMockProxy<PrismaClient>;
};

export const createMockContext = (): MockContext => {
  return {
    prisma: mockDeep<PrismaClient>(),
  };
};
I'm getting the following error:
Copy code
Type '{ $on: CalledWithMock<void, [eventType: "beforeExit", callback: (event: () => Promise<void>) => void]>; $connect: CalledWithMock<Promise<void>, []>; ... 13 more ...; readonly subMenu: DeepMockProxy<...>; } & PrismaClient<...>' is not assignable to type 'DeepMockProxy<PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>>'.
      Type '{ $on: CalledWithMock<void, [eventType: "beforeExit", callback: (event: () => Promise<void>) => void]>; $connect: CalledWithMock<Promise<void>, []>; ... 13 more ...; readonly subMenu: DeepMockProxy<...>; } & PrismaClient<...>' is not assignable to type '{ $on: CalledWithMock<void, [eventType: "beforeExit", callback: (event: () => Promise<void>) => void]>; $connect: CalledWithMock<Promise<void>, []>; ... 13 more ...; readonly subMenu: DeepMockProxy<...>; }'.
        The types of '$on.calledWith' are incompatible between these types.
          Type '(...args: [eventType: "beforeExit", callback: (event: () => Promise<void>) => void] | [eventType: "beforeExit" | import("/Users/siemenblok/station21/node_modules/jest-mock-extended/lib/Matchers").Matcher<"beforeExit">, callback: ((event: () => Promise<...>) => void) | import("/Users/siemenblok/station21/node_modules...' is not assignable to type '(...args: [eventType: "beforeExit", callback: (event: () => Promise<void>) => void] | [eventType: "beforeExit" | import("/Users/siemenblok/station21/node_modules/jest-mock-extended/lib/cjs/Matchers").Matcher<"beforeExit">, callback: ((event: () => Promise<...>) => void) | import("/Users/siemenblok/station21/node_mod...'.
            Types of parameters 'args' and 'args' are incompatible.
              Type '[eventType: "beforeExit", callback: (event: () => Promise<void>) => void] | [eventType: "beforeExit" | import("/Users/siemenblok/station21/node_modules/jest-mock-extended/lib/cjs/Matchers").Matcher<"beforeExit">, callback: ((event: () => Promise<...>) => void) | import("/Users/siemenblok/station21/node_modules/jest-...' is not assignable to type '[eventType: "beforeExit", callback: (event: () => Promise<void>) => void] | [eventType: "beforeExit" | import("/Users/siemenblok/station21/node_modules/jest-mock-extended/lib/Matchers").Matcher<"beforeExit">, callback: ((event: () => Promise<...>) => void) | import("/Users/siemenblok/station21/node_modules/jest-mock...'.
                Type '[eventType: "beforeExit" | Matcher<"beforeExit">, callback: ((event: () => Promise<void>) => void) | Matcher<(event: () => Promise<void>) => void>]' is not assignable to type '[eventType: "beforeExit", callback: (event: () => Promise<void>) => void] | [eventType: "beforeExit" | Matcher<"beforeExit">, callback: ((event: () => Promise<void>) => void) | Matcher<(event: () => Promise<...>) => void>]'.
                  Type '[eventType: "beforeExit" | Matcher<"beforeExit">, callback: ((event: () => Promise<void>) => void) | Matcher<(event: () => Promise<void>) => void>]' is not assignable to type '[eventType: "beforeExit", callback: (event: () => Promise<void>) => void]'.
                    Type at position 0 in source is not compatible with type at position 0 in target.
                      Type '"beforeExit" | Matcher<"beforeExit">' is not assignable to type '"beforeExit"'.
                        Type 'Matcher<"beforeExit">' is not assignable to type '"beforeExit"'.

    15     prisma: mockDeep<PrismaClient>(),
           ~~~~~~

      context.ts:10:3
        10   prisma: DeepMockProxy<PrismaClient>;
             ~~~~~~
        The expected type comes from property 'prisma' which is declared here on type 'MockContext'
Does anyone know why? Or how I can fix this?
Noone?