anyone have experience mocking Prisma in Jest? I'v...
# orm-help
j
anyone have experience mocking Prisma in Jest? I've been using
jest-mock-extended
and using
mockDeep
to create typed mocks. However, after upgrading to latest 2.20.1 from 2.19.0, I'm receiving a typescript error.
Copy code
Type of property 'OR' circularly references itself in mapped type '{ [K in keyof { AND?: Enumerable<WorkplaceScalarWhereWithAggregatesInput>; OR?: Enumerable<WorkplaceScalarWhereWithAggregatesInput>; ... 12 more ...; updatedAt?: string | ... 1 more ... | DateTimeWithAggregatesFilter; }]: Or<...> extends 1 ? { ...; }[K] extends infer TK ? GetHavingFields<...> : never : {} extends Fi...'.
šŸ‘€ 1
šŸ‘ 1
n
Hey James šŸ‘‹ I'm unsure about your specific error unfortunately but for some general guidance on using Prisma with Jest I'd recommend this article (by our awesome community member @Eddy Nguyen): How to write tests for Prisma with Docker and Jest
ā¤ļø 2
j
@nikolasburk thanks for the article. However the article currently only covers performing an integration or end to end test and assumes the code will have an active database running. I'm working towards unit tests where database calls will be mocked and probably spied upon.
Given the strongly typed interface that is returned from Prisma, I think it's vital for us to have a valid method to mock out the Prisma client that is returned. Would ultimately like it to work with something like
mockDeep
that can automatically created a typed mock. Anything manual would be really hard to write without explicit TS ignores all over the place.
šŸ’Æ 1
j
Did you have any luck with mocking prisma?
j
i have resorted to using ts ignore
@nikolasburk I’d like to add that the mockDeep used to work before the 2.20.1 upgrade.
j
@James Lee in case you are still finding a better way: I ran into the same issue and resolved it by adding this in tsconfig:
Copy code
{
  "compilerOptions": {
    [...]
    "strict": true,
    "strictNullChecks": true,
    "strictPropertyInitialization": true,  
  }
}
j
@Jean-Philippe BOIS TY. will give this a shot and see if it works for m.e
yo, tried it out and it works!
šŸ‘ 1
although i have to go and refactor in many places for strictNullChecks