Description
Problem
I'd like to have the unit testing of code working with prisma be more precise about what is being passed into and returned from the mocked prisma method. The examples in the documentation make use of mockResolvedValue
(with the same data passed into the tested object as is returned by the prisma method) but I'd like to use mockImplementation
so I can ensure the prisma method is working with the data that was actually supplied to it.
Suggested solution
Allow (or document if it is already possible) alternative mocking techniques.
Additional context
The suggested mocking solution
test('should create new user ', async () => {
const user = {
id: 1,
name: 'Rich',
email: 'hello@prisma.io',
acceptTermsAndConditions: true,
}
prismaMock.user.create.mockResolvedValue(user)
await expect(createUser(user)).resolves.toEqual({
id: 1,
name: 'Rich',
email: 'hello@prisma.io',
})
})
would still pass even if the implementation of createUser
was:
export async function createUser(user: CreateUser) {
return await prisma.user.create({
data: {id: user.id, name: user.name},
});
}
i.e. the failure by the function to pass the email value down to prisma is not shown by the test.
I've tried using create.mockImplementation
but get the equivalent of
Type 'Promise<User>' is missing the following properties from type 'Prisma__UserClient<User>': _dmmf, _fetcher, _queryType, _rootField, and 10 more.