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

156
Visualizações
chair + supertest + promises confusion - .end being called twice due to a .then?

I have a function stored in a separate file which has a call to a graphql endpoint.

I am trying to call this function and return an id (which is returned) - however, I am getting an warning that I am using .end and .done

The function:

module.exports = {
    addThing: async function (title, extRef, done) {
        const basicAddCreative = `mutation { ...}`

        let the_id = await request
        .post("/graphql")
        .send({
            query: basicAddCreative
        })
        .set("Accept", "application/json")
        .expect(200)
        .end((err, res) => {
            if (err) return done(err)
            return res.body.data.id
        })
        return the_id
    }
}

And this is called (in a different file)

let cId = helpers.addThing('fnTest', 'fnTest', done)
cId.then(i => console.log(i))

And then when I run this the test I have fails for : .end() was called twice. This is not supported in superagent And then I see: Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises.

Can anyone shed light on how I could fix the above? Specifically, if I am using supertest with chai, I need to use the .end (or supertest will mark the query as fail for timingout) - and I need to use .then to get the return value. So, how is this possible?

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