nestjs-prisma icon indicating copy to clipboard operation
nestjs-prisma copied to clipboard

applicationRef undefined in nest e2e tests

Open lays147 opened this issue 2 years ago • 1 comments

Hello, I'm using nestjs-prisma in an application, and I have an e2e test failing when an exception is launched because the applicationRef inside this lib is undefined.

Steps to reproduce:

  • Write an e2e test where you expect an exception to be raised using the findFirstOrThrow inside a nest service and call it through the controller.

Expected behavior:

The test passes without issues.

What is happening:

The exception is properly raised, however, the applicationRef is undefined making the test hang with:

    TypeError: Cannot read properties of undefined (reading 'isHeadersSent')

      at PrismaClientExceptionFilter.catch (node_modules/@nestjs/core/exceptions/base-exception-filter.js:27:29)
      at PrismaClientExceptionFilter.catchClientKnownRequestError (node_modules/nestjs-prisma/lib/prisma-client-exception.filter.ts:88:6)
      at PrismaClientExceptionFilter.catch (node_modules/nestjs-prisma/lib/prisma-client-exception.filter.ts:69:4)
      at ExceptionsHandler.invokeCustomFilters (node_modules/@nestjs/core/exceptions/exceptions-handler.js:33:26)
      at ExceptionsHandler.next (node_modules/@nestjs/core/exceptions/exceptions-handler.js:13:18)
      at node_modules/@nestjs/core/router/router-proxy.js:13:35

This issue does not happen in runtime.

Here is a thread on the NestJS discord server discussing about this bug.

lays147 avatar Aug 10 '23 23:08 lays147

related with this: https://github.com/nestjs/nest/issues/12217

micalevisk avatar Aug 11 '23 03:08 micalevisk