vitest-prisma-dual-query-mocking
Installation
SKILL.md
Vitest Prisma Dual Query Mocking
Problem
When code uses both findFirst and findUnique on the same Prisma/ZenStack model, a single
mock implementation doesn't work correctly. One query returns the mocked data while the other
returns undefined, causing test failures.
Context / Trigger Conditions
- Test error: "Cannot read properties of undefined (reading 'value')" or similar
- Code uses
db.model.findFirst({ where: {...} })for one query - Code uses
db.model.findUnique({ where: { composite_key: {...} } })for another query - Both queries target the same model (e.g.,
userPreference) - Single mock like
mockDb.model.findFirst = vi.fn().mockResolvedValue(data)doesn't cover both - Tests pass individually but fail when both queries run in same test