Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript circular reference when testing prisma with jest-mock-extended

I started writting tests revolving around prisma(v3.6.0) usage in my application.

To do so I followed the official prisma page Unit testing with prisma and I am using jest-mock-extended.

My issue is that I have a typescript error when using the mocked prisma functions :

describe('User routes', () => {
    it('should respond success with array of users', async () => {
        prismaMock.user.findMany.mockResolvedValue([]); // <- here is the error
    }
}
Type of property 'AND' circularly references itself in mapped type 

There is some discussion about this issue on github Testing with prisma. I got 3 options from this discussion :

  • Adding "skipLibCheck": true in tsconfig.json. This breaks some things in my code and doesn't resolve my issue
  • Adding "strictNullChecks": true, no effect either
  • //@ts-ignore the line. This effectively remove the error, and the test runs smoothly

While I am able to do my tests, I would like not to have to ignore this error everywhere in my tests, and ignoring errors is only a good idea until it's not.

Does someone have more information or recommendations about this issue ?

like image 384
EoiFirst Avatar asked Dec 10 '25 03:12

EoiFirst


1 Answers

Set the "stricNullChecks": true in your tsconfig.json, it is highlighted on prisma documentation for the circular dependency error.

https://www.prisma.io/docs/orm/prisma-client/testing/unit-testing

like image 146
Marco Martins Avatar answered Dec 11 '25 19:12

Marco Martins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!