morintd / prismock

A mock for PrismaClient, dedicated to unit testing.
https://www.npmjs.com/package/prismock
MIT License
190 stars 21 forks source link

Delete on prisma models throws an error #935

Closed mxrcochxvez closed 2 months ago

mxrcochxvez commented 4 months ago

For privacy reasons I am going to make this code as ambiguous as possible. However the concept very closely follows what I am trying to achieve.

posts.repo.ts

export const postsRepo = { deletePosts };

function deletePosts(postId: string) {
    return prisma.posts.delete({ where: { id: postId } });
}

mock-prisma.ts (setupTests method)

jest.mock('@prisma/client', () => {
    return {
        ...jest.requireActual('@prisma/client'),
        PrismaClient: jest.requireActual('prismock').PrismockClient,
    };
});

posts.spec.ts

test('it should delete a post', async () => {
    try {
        const result = await postsRepo.deletePosts('1');

        expect(results).toBeTruthy();
    } catch(error) {
        console.log(error);
    }
})

I am getting the following error

image
morintd commented 4 months ago

Hello @mxrcochxvez , thanks a lot. Unfortunately, I don't have enough information to find where this issue is coming from. This might be related to your specific use case, would you be able to create a minimum reproductible example on a public repository? Maybe you have more information on the error too?