Skip to content

Commit 9631a24

Browse files
committed
use experimentalRollbackInTransaction
1 parent 85f9367 commit 9631a24

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

jest.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export default {
66
setupFilesAfterEnv: [],
77
testEnvironmentOptions: {
88
verboseQuery: true,
9+
enableExperimentalRollbackInTransaction: true,
910
},
1011
};

src/index.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export async function ensureUser(
88
}
99
): Promise<boolean> {
1010
try {
11-
await prisma.user.create({ data });
11+
await prisma.$transaction(async () => {
12+
await prisma.user.create({ data });
13+
});
1214
return true;
1315
} catch (err: any) {
1416
const uniqConstraintFailed = err.code === "P2002";
@@ -31,6 +33,10 @@ test(ensureUser.name, async () => {
3133
// succeed
3234
expect(await ensureUser(jestPrisma.client, data)).toBe(true);
3335

34-
// fail
36+
// succeed
3537
expect(await jestPrisma.client.user.count()).toBe(1);
3638
});
39+
40+
test("count user", async () => {
41+
expect(await jestPrisma.client.user.count()).toBe(0);
42+
});

0 commit comments

Comments
 (0)