Skip to content

Mock Prisma client #2152

Answered by Romakita
thermsdorff asked this question in Q&A
Nov 10, 2022 · 1 comments · 5 replies
Discussion options

You must be logged in to vote

Hello @thermsdorff,

You can try that:

import { PrismaClient } from '@prisma/client'
import { mockDeep, mockReset, DeepMockProxy } from 'jest-mock-extended'

export function mockPrismaService() {
   registerProvider({
      provide: PrismaService,
      useClass: null,
      useFactory: () => {
        return mockDeep<PrismaClient>()
      },
      hooks: {
        $onDestroy(instance: any) {
           mockReset(instance);
        }
      }
   })
}
export function restorePrismaService() {
     registerProvider({provide: PrismaService, useClass: PrismaService})
}

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@thermsdorff
Comment options

@Romakita
Comment options

@thermsdorff
Comment options

@Romakita
Comment options

@Romakita
Comment options

Answer selected by thermsdorff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants