Closed fzn0x closed 3 years ago
I'll close this issue, the solution is to use .then(done,done)
, the reason for that is because agent itself returning two promises in that one test case.
agent
.post("/api/auth/login") // to get jwtToken
.send({
email: "cantbehacked@gmail.com",
password: "fakepasswordforgithubissue",
})
.then((res) => {
return agent
.post("/api/documents")
.set(CONFIG.tokenHeaderKey, `Bearer ${res.body.token}`)
.attach("cool_sample1", "./test/samples/sample-number-1-bro.jpg")
.attach("cool_sample2", "./test/samples/sample-number-2-bro.jpg")
.attach("cool_sample3", "./test/samples/sample-number-3-bro.jpg")
.then((res) => {
console.error(res.body);
expect(res).to.have.status(200);
}).then(done, done);
})
.catch(function (err) {
throw err;
});
I hope it helps everyone :)
I'm using https://github.com/anacronw/multer-s3 with https://www.npmjs.com/package/aws-sdk
there is something odd when I use chai-http which leads to an API that uses middleware with those libraries, where if I call the
done
function after theexpect
code or return an async function in the test functionit
, the middleware function from the library does not run.However when I call the
done
function before theexpect
code, the middleware function of it runs but none of the test function from chai is work, is this could be considered as a bug?