Quiero guardar algunos datos de un cuerpo y usarlos con la próxima solicitud en mis pruebas. Estoy haciendo una solicitud de publicación y obtengo una identificación. Esta identificación que quiero usar para obtener datos en otra prueba.
Mi código se ve así:
it('/auth/register (POST)', async () => { const test = await request(app.getHttpServer()) .post('/api/auth/register') .send({username: "Zoe"}) .expect(201) token = test.body.token })El token se está configurando y el código se ejecuta, sin embargo, mi prueba de broma no se detendrá y obtendré el error:
Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.Sé que puedo forzar la salida pero quiero hacerlo limpio y entender el problema.
Cuando hago el método de retorno de broma, está funcionando... Sin embargo, no sé cómo almacenar el cuerpo en algún lugar...
it('/auth/register (POST)', () => { request(app.getHttpServer()) .post('/api/auth/register') .send({username: "Zoe"}) .expect(201) })Resolví este problema cerrando la conexión de la base de datos cuando la aplicación se está cerrando
import { Module } from '@nestjs/common'; import { getConnection } from 'typeorm'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { DatabaseModule } from './database/database.module'; import { FormsModule } from './forms/forms.module'; @Module({ imports: [ DatabaseModule, FormsModule, ], controllers: [AppController], providers: [AppService], }) export class AppModule { onApplicationShutdown(){ getConnection().close(); } } ```