POST, Promise never resolves
See original GitHub issueI 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:
- Created 2 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
I am having the same issue.