I understand this post is a little old and you probably found a way to mock prisma. But in case someone stumbles here for help, the "jest-mock-extended" library can efficiently help in mocking prisma.
How:
import { mockDeep, DeepMockProxy } from 'jest-mock-extended' import { PrismaClient } from '@prisma/client'; .. .. .. describe('Cats (e2e)', () => { let mockPrisma: DeepMockProxy<PrismaClient>; .. .. .. beforeEach(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ imports: [AppModule], }) .overrideProvider(PrismaService) .useValue(mockDeep<PrismaClient>()) .. .. .compile(); .. .. mockPrisma = moduleFixture.get(PrismaService); await app.init(); }) .. .. it('Creates a new cat', async () => { mockPrisma.cat.create.mockResolvedValueOnce(mockCat); const res = await request(app.getHttpServer()).post('/cats').send({}); expect(res.status).toBe(201); expect(res.body).toStrictEqual(mockCatResponse); }); .. .. })
Thanks a lot. I will try! Have a nice day
Thanks, this was exactly what I was looking for!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I understand this post is a little old and you probably found a way to mock prisma. But in case someone stumbles here for help, the "jest-mock-extended" library can efficiently help in mocking prisma.
How:
Thanks a lot. I will try!
Have a nice day
Thanks, this was exactly what I was looking for!