DEV Community

Discussion on: How to write tests for Prisma with Docker and Jest

Collapse
 
eddeee888 profile image
Eddy Nguyen

Hi James!

I normally have 2 databases, one for dev and one for test to separate the concerns. For the test database, I normally reset it before running new tests.

For newer versions of Prisma ( >v2.16 I think ), you can run the following command to clear the database:
yarn prisma migrate reset --skip-seed

Here' an example of a simple script that I use to run tests with some flags for different use case: github.com/eddeee888/base-app-mono...

With that script, you can do something like this:

# Run tests after resettting the test database
$ ./scripts/test-app.sh 

# Run tests without resetting the test database
$ ./scripts/test-app.sh --noreset

# Run tests after rebuilding docker images and resetting database
$ ./scripts/test-app.sh --rebuild
Enter fullscreen mode Exit fullscreen mode

I will update the post to make it clearer when I find time. Thanks for the question! 🙌

Collapse
 
philbrockman profile image
Phil Brockman

Been looking at tutorials for Next.js + Prisma + Jest for a good amount of time. So many purple links on Google...

Even though the focus of this article is a slightly different stack, completing these steps lead to my first passed test!

Thank you for sharing.