import { Test , TestingModule } from '@nestjs/testing' ; import * as request from 'supertest' ; import { AppModule } from '../src/app.module' ; import { INestApplication } from '@nestjs/common' ; const requestFunction = ( url , data , app ) => request ( app . getHttpServer ( ) ) . get ( url ) . expect ( data . status ) . expect ( data . data ) ; describe ( 'AppController (e2e)' , ( ) => { let app ; beforeAll ( async ( ) => { const moduleFixture = await Test . createTestingModule ( { imports : [ AppModule ] , } ) . compile ( ) ; app = moduleFixture . createNestApplication ( ) ; app . useLogger ( false ) ; await app . init ( ) ; } ) ; afterAll ( async ( ) => { await app . close ( ) ; } ) ; it ( '/ (GET)' , ( ) => { return requestFunction ( '/' , { data : { statusCode : 500 , message : 'Internal server error' } , status : 500 , } , app ) ; } ) ; it ( '/?takeAmount=10&maxVal=50' , ( ) => { return requestFunction ( '/?takeAmount=10&maxVal=50' , { data : '10' , status : 200 } , app ) ; } ) ; } ) ;