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

153
Views
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
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!