Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda