15

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 ?

Yabada
  • 1,728
  • 1
  • 15
  • 36

1 Answers1

-1

Thanks for the thread i was about to open one myself, my understanding is that this is due to the TS check on the prisma lib, the fix that worked for me was to add these to your TS config:

"skipLibCheck": true,
"strictNullChecks": true

I am aware that "skipLibCheck" may break things in your code, but i think that it may be the correct approach, as it will reduce compilation time and a check against 3rd parties lib's (assuming they are 3rd party d.ts files) is not "ususally" necessary.

Jeremy
  • 1,170
  • 9
  • 26