Thanks for the detailed post. Just wondering, if you keep creating new users like that will your database end up with lots of junk data? Maybe, you need to mock the creating of the user instead of actually create one? I guess you have to rewrite the whole test then...
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
# 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
I will update the post to make it clearer when I find time. Thanks for the question! 🙌
Thanks for the detailed post. Just wondering, if you keep creating new users like that will your database end up with lots of junk data? Maybe, you need to mock the creating of the user instead of actually create one? I guess you have to rewrite the whole test then...
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:
I will update the post to make it clearer when I find time. Thanks for the question! 🙌
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.