Jordan Renaud
Jordan Renaud

Reputation: 180

Prisma 2 not working well with NestJS spec testing

I'm playing with NestJS, and setting it up with Prisma 2. My issue as of now is with testing. My failed tests are all to do with the entity object not existing in the PrismaService. For example, every single failed test looks like this, but maybe a different entity type:

src/user/user.service.ts:25:24 - error TS2339: Property 'user' does not exist on type 'PrismaService'.

    25     return this.prisma.user.findUnique({ where: userWhereUniqueInput });

The tests being run are the default tests generated by nest cli for resources. My PrismaService is just a class that extends PrismaClient and overrides the shutdown hook method and init/destroy lifecycle methods, as nestJS provides in their Prisma2 example. Is this a module import/export problem or just a compatibility issue between prisma/nestjs/jest? My modules all import required modules and export their services/providers, so I'm not sure what's happening here, unless some pre-testing setup needs to be done.

Upvotes: 0

Views: 1349

Answers (1)

Jordan Renaud
Jordan Renaud

Reputation: 180

As it turns out, I wasn't importing the PrismaModule in my test suites. Also, a secondary issue that contributed to these failures was the fact that the PrismaService was being imported using absolute paths (/src/prisma/prisma.module) rather than the relative path (../prisma/prisma.module)

Upvotes: 0

Related Questions