question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

POST, Promise never resolves

See original GitHub issue

I am doing this unit test with supertest and chai and I do it in these two way

it("POST /novedades/api/postSolicitudVacaciones (servicio de guardar una solicitud de vacaciones)  ", (done) => {
    request(app)
        .post("/novedades/api/postSolicitudVacaciones")
        .send({
            dtFechaInicio: "2021-07-30",
            intNumeroDiasDisfrutar: 3,
            intNumeroDiasCompensar: 0,
            arrAprobadores: "scardonas@domain.com"
        })
        .set({ token: token, Accept: "application/json" })
        .expect((res) => {
            console.log(res)
            expect(res.body).to.have.property("error", false);
        })
        .expect(200)
        .end((err) => {
            if (err) throw new Error(err)
        })
})
it("POST /novedades/api/postSolicitudVacaciones (servicio de guardar una solicitud de vacaciones)  ", async() => {

        await agent
            .post("/novedades/api/postSolicitudVacaciones")
            .send({
                dtFechaInicio: "2021-07-30",
                intNumeroDiasDisfrutar: 3,
                intNumeroDiasCompensar: 0,
                arrAprobadores: "scardonas@domain.com"
            })
            .set({ token: token, Accept: "application/json" })
            .expect("Content-Type", /json/)
            .expect(200)
            .then((err, res) => {
                console.log(res.body);
                expect(res.body).to.have.property("error", false);
            })
 });

And in both cases I always get the error 'Timeout of 2000ms exceeded. For async tests and hooks, ensure “done ()” is called; if returning a Promise, ensure it resolves. ’ and the test performs the unit test well because he saves in BD

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
iamthegDcommented, May 24, 2022

Make sure the actual API works. Was having the same problem with an exception uncatched inside main application. Would not show in log so I was thinking all this async stuff was going wrong.

Finally I had to resolve to use supertest like this for async await to work. const supertestInstance = require(‘supertest’)(“http://localhost:3000/api”);

Otherwise if you consume the app directly the async calls are SLOW/crawled by something which I did not find. With a long enough timeout I could see the post async test beeing receive minutes later on the supertest logs.

0reactions
rdgomtcommented, Aug 11, 2022

I am having the same issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Promise Never Resolves Using Axios - Stack Overflow
Have you tried calling the method using await axios.post(. ... the function called by then will never return anything but a void promise....
Read more >
POST, Promise never resolves · Issue #727 · ladjs/supertest
I am doing this unit test with supertest and chai and I do it in these two way it("POST /novedades/api/postSolicitudVacaciones (servicio de ...
Read more >
Detecting a promise that will never resolve/ reject
I ran into an interesting JavaScript problem today: How to detect a promise that will never resolve/ reject?
Read more >
Promise.all() - JavaScript - MDN Web Docs
const promise3 = new Promise((resolve, reject) => { ... Using setTimeout, we can execute code after the queue is empty setTimeout(() ...
Read more >
Handling JavaScript Promises with Async/Await or .then |
After the promise is created, the promise will automatically call the executor. This executor has two arguments dubbed “resolve” and “reject” which are ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found