Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

353
Views
No funciona la prueba con JestJS que cierra la aplicación

Amigos, tengo un problema!

Estoy probando mi API con NestJS. Estoy usando Jest para la prueba. Desafortunadamente, me encuentro con el siguiente error:

TypeError: no se pueden leer las propiedades de undefined (leyendo 'cerrar')

Este error es muy explícito pero no veo de dónde puede venir.

¿Tendrías una idea?

Mi código actual:

 import * as pactum from 'pactum'; import { Test } from '@nestjs/testing'; import { AppModule } from '../src/app.module'; import { INestApplication, ValidationPipe } from '@nestjs/common'; import { PrismaService } from '../src/prisma/prisma.service'; import { AuthDto } from '../src/auth/dto'; describe('App e2e', () => { let app: INestApplication; let prisma: PrismaService; beforeAll(async () => { const moduleRef = await Test.createTestingModule({ imports: [AppModule], }).compile(); const app = moduleRef.createNestApplication(); app.useGlobalPipes( new ValidationPipe({ whitelist: true, }), ); await app.init(); await app.listen(3334); prisma = app.get(PrismaService); await prisma.cleanDatabase(); }); afterAll(async () => { console.log('Closing server'); await app.close(); // <------------- THE PROBLEM ARISES HERE. }); describe('Auth', () => { describe('Signup', () => { it('should signup a user', () => { const dto: AuthDto = { email: 'darrel.doe@mail.com', password: '1234', }; return pactum .spec() .post('http://localhost:3333/auth/signup') .withBody(dto) .expectStatus(201); }); }); describe('Signin', () => { it.todo('should signin a user'); }); }); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Estás mezclando dos variables en diferentes ámbitos.

let app: INestApplication; es el alcance superior que está utilizando realmente, ya que no tiene ningún valor asignado, no está undefined . El interno es diferente porque está definiendo dentro de otro ámbito.

Una solución es muy simple, simplemente elimine const de const app = moduleRef.createNestApplication();

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!