import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppModule } from '../src/app.module';
describe('AppController (integration)', () => {
let app: INestApplication;
beforeAll(async () => {
const moduleRef: TestingModule = await Test.createTestingModule({ imports: [AppModule] }).compile();
app = moduleRef.createNestApplication();
await app.init();
});
it('/GET hello', () => {
return request(app.getHttpServer())
.get('/hello')
.expect(200)
.expect('Hello World!');
});
afterAll(async () => {
await app.close();
});
});This code sets up a NestJS app for testing, sends a GET request to '/hello', checks the response, then closes the app.