Most examples I've seen of how to test a Prisma-injected NestJS Service (e.g. prisma-sample
in testing-nestjs
) are for "end to end" testing. They actually access the database, performing actual queries and then rolling back the results if necessary.
For my current needs, I want to implement lower-level "integration" testing.
As part of this, I want to remove Prisma from the equation. I want the focus to be on my service's functionality instead of the state of data within the database and Prisma's ability to return it.
One big win of this approach is that it obviates the need to craft "setup" queries and "teardown"/reset operations for specific tests. Instead, I'd like to simply manually specify what we would expect Prisma to return.
In an environment consisting of NestJS, Prisma, and Jest, how should I accomplish this?
UPDATE: The author of the testing-nestjs project pointed out in the comments that the project does have an example of database mocking. It looks nice! Others may still be interested in checking out the Gist that I've linked to as it includes some other useful functionality.