Skip to content

Commit

Permalink
use experimentalRollbackInTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Quramy committed Mar 26, 2024
1 parent 85f9367 commit 9631a24
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions jest.config.mjs
Expand Up @@ -6,5 +6,6 @@ export default {
setupFilesAfterEnv: [],
testEnvironmentOptions: {
verboseQuery: true,
enableExperimentalRollbackInTransaction: true,
},
};
10 changes: 8 additions & 2 deletions src/index.test.ts
Expand Up @@ -8,7 +8,9 @@ export async function ensureUser(
}
): Promise<boolean> {
try {
await prisma.user.create({ data });
await prisma.$transaction(async () => {
await prisma.user.create({ data });
});
return true;
} catch (err: any) {
const uniqConstraintFailed = err.code === "P2002";
Expand All @@ -31,6 +33,10 @@ test(ensureUser.name, async () => {
// succeed
expect(await ensureUser(jestPrisma.client, data)).toBe(true);

// fail
// succeed
expect(await jestPrisma.client.user.count()).toBe(1);
});

test("count user", async () => {
expect(await jestPrisma.client.user.count()).toBe(0);
});

0 comments on commit 9631a24

Please sign in to comment.