Current section: End-to-End 6 exercises

Proper Setup and Teardown of Testing for Database Cleanup

Loading solution


00:00 Yeah, yeah, okay, this one was pretty quick, but it is important, and that's why it deserves its own step in this exercise. It's literally just await Prisma user delete, where the user ID matches the ID of the user that we got. So let's add our ID right here,

00:18 and we could also do their username, because that's a unique field as well, but there we go. So we delete the user when we're all done. So we've got four users, if I run it again, four extra users, if I run it again, then we still only have four extra users. You could re-save your database to start from a clean slate,

00:36 but the point is that we're not leaving any users in the database that shouldn't be there by the end of this test. Unfortunately, this doesn't completely solve the issue, and so while you thought this was an easy thing to do, there's actually a little bit more to it that we'll look at next. But yeah, that's the basic principle is you make a mess,

00:56 and then you clean up after yourself. That's all the setup and teardown of testing.