Is your feature request related to a problem? Please describe.
Is there a simple way to mock Prisma for unit testing? What are the best practices?
Describe the solution you'd like
For instance it would be neat to be able to create an instance of prisma client with dummy data in memory. Something like that:
import { Prisma } from '@generated/prisma-client';
const db = new Prisma({
mockData: {users: [{name: "myUser", password: "myUserPassword"}] }
debug: config.isDev!,
});
export default db;
And we could inject that mocked Prisma instance in the context for unit test purspose and use it like a real Prisma.
Describe alternatives you've considered
At the moment we have to mock every prisma functions like this:
const db = {
users: args => ({name: "myUser", password: "myUserPassword"}),
createUser: args => ({...args})
$exists: {
users: (args) => true
}
...
}
Hi @durdenx,
I don't think currently there is a solution baked into prisma for this so we can use this issue as a feature request.
That being said I use this approach currently to mock the prisma client and it works fine. Have a look 馃檪
Thanks @pantharshit00! It's a very useful link 馃憤
This would be important for the Go client as well.
+1
Most helpful comment
Hi @durdenx,
I don't think currently there is a solution baked into prisma for this so we can use this issue as a feature request.
That being said I use this approach currently to mock the prisma client and it works fine. Have a look 馃檪