You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug Report: Factory Usage in Jest Hooks with jest-prisma
Description
Using Factory utilities in beforeAll()/afterAll() Jest hooks with jest-prisma results in transaction errors. The package's transaction wrapper is only active during test cases (it blocks) or beforeEach/afterEach hooks, causing Factory operations in beforeAll/afterAll to fail.
Error Message
Error: jestPrisma.client should be used in test or beforeEach functions because transaction has not yet started.
Factory utilities should work in all Jest lifecycle hooks when using jest-prisma.
Actual Behavior
Factory usage in beforeAll/afterAll throws transaction errors.
Workaround
Use jestPrisma.originalClient directly for setup/teardown in hooks:
beforeAll(async()=>{// ✅ Works with raw queries awaitjestPrisma.originalClient.user.create({data: {email: '[email protected]',// ... other required fields }});});
Suggested Fixes
Allow Factory patterns to use originalClient internally for hooks.
Document this limitation and provide migration examples.
Bug Report: Factory Usage in Jest Hooks with
jest-prisma
Description
Using Factory utilities in
beforeAll()
/afterAll()
Jest hooks withjest-prisma
results in transaction errors. The package's transaction wrapper is only active during test cases (it
blocks) orbeforeEach
/afterEach
hooks, causing Factory operations inbeforeAll
/afterAll
to fail.Error Message
Reproduction Steps
Create a test suite with
jest-prisma
.Use Factory in a
beforeAll
hook:Run tests and observe the transaction error.
Expected Behavior
Factory utilities should work in all Jest lifecycle hooks when using
jest-prisma
.Actual Behavior
Factory usage in
beforeAll
/afterAll
throws transaction errors.Workaround
Use
jestPrisma.originalClient
directly for setup/teardown in hooks:Suggested Fixes
originalClient
internally for hooks.Code Example (Failure vs. Success)
❌ Fails in
beforeAll
/afterAll
✅ Works in
beforeEach
/it
Impact
Forces developers to:
Priority: High
Severity: Major (reduces code maintainability)
The text was updated successfully, but these errors were encountered: