I'm new to nest js and trying to understand how E2E tests work. I created a simple route where I add up the summation of two numbers.
In the browser and in the http client the value 11 comes to me, but in the test for some reason nothing comes except code 200.
import * as request from 'supertest';
import { Test } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { MathModule } from './math.module';
describe('MathE2E', () => {
let app: INestApplication;
beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
imports: [MathModule],
}).compile();
app = moduleRef.createNestApplication();
await app.init();
});
it(`/GET math/sum`, () => {
return request(app.getHttpServer())
.get('/math/sum?operand1=5&operand2=6')
.expect(200)
.expect({
data: 11,
});
});
afterAll(async () => {
await app.close();
});
});