I'm using supertest and jest to write my test. but the delete and put routes in particular don't work properly, it keeps waiting until it times out.
My speculations tells me that the route is not being hit because i tried to log something in the route but it doesn't. So, i must be doing something wrong with supertest
. Also, Im using methodoverride
.
// test.js
const request = require("supertest");
const app = require("../app");
let server = request(app);
const aQuestionId = "5c78b8906c20cc5d22360a87";
test("DELETE /questions/:qID", done => {
jest.setTimeout(10000);
server
// /questions/5c7899a24552624a5b9c7f35?_method=DELETE
.delete(`/questions/${aQuestionId}`)
.expect(200);
});
// Delete route
// DELETE /questions/:qID
router.delete("/questions/:qID", question.deleteQuestion);
The problem was that, I wasn't calling done when i complete my request which kept the connection open and then jest times out because request not closed
test("DELETE /questions/:qID", done => {
jest.setTimeout(10000);
server
// /questions/5c7899a24552624a5b9c7f35?_method=DELETE
.delete(`/questions/${aQuestionId}`)
.expect(200, done); <= call done
});