What is the simplest way to test prisma service (prisma.service.ts)?

Viewed 22

Let's assume the primsa.service.ts files look likes this. Can anyone suggest what would be the simplest way to test this particular file covering both the methods in nestjs testing.

import { INestApplication, Injectable, OnModuleInit } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';

@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {

  constructor() {
    super({
      ...(process.env.NODE_ENV === "development" ? {
        log: ['query', 'info', 'warn', 'error']
      } : {}),
      datasources: {
        db: {
          url: process.env.DATABASE_URL + '?connection_limit=20',
        },
      },

    })
  }

  async onModuleInit() {
    await this.$connect();
  }

  async enableShutdownHooks(app: INestApplication) {
    this.$on('beforeExit', async () => {
      await app.close();
    });
  }
}```
0 Answers
Related