How to setup and teardown database records when running integration tests with trpc?

Currently, I'm doing this but it seems impractical to do with more tables in the database. Is there an alternative approach?
afterEach(async () => {
const ctx = await createContextInner({
session: null,
});

await ctx.prisma.record.deleteMany();
// more records here...
});
afterEach(async () => {
const ctx = await createContextInner({
session: null,
});

await ctx.prisma.record.deleteMany();
// more records here...
});
I also run into errors where certain tables still contain records which means it's not cleaned up properly after running tests. Thanks in advanced! ❤️
2 Replies
Neto
Neto3y ago
maybe something like
Neto
Neto3y ago
the idea is used in frameworks like nestjs as a example

Did you find this page helpful?