Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
How do I do api jest testing with BDD style in NodeJs Jest?

The test below is passing. However there'd be no coverage. Apparently the promise does not resolve which is always in pending state. What I did is to break the Promise chain and put the pieces in two different functions to make it look like BDD style.

How do I get that covering my code. Any help would be much appreciated?

NodeJs 14.17.3 ts-jest 27.4.1 Jest 27.4.1.

const request = require('supertest')

let res:Promise<any>
let a:string
let b:string

it('should return ....', async () => {
   given('', '')
   when()
   then()
}

async function given(a:string, b:string) {
   // assignments go here 
}

async function when() {
   cons runPro = async (): Promise<any> => {
       return new Promise((resolve, reject) => {
             request(baseurl).get('theurl').then((value:any) => {
                  resolve(value.body)
             }).catch(error => {
                  reject(err)
              })
         }).catch(error => {
            // 
         }
     }
      res = runPro()
}

async function then() {
     res.then(value => {
        expect(value).toEqual("")
    }
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda