I'm having an argument with a co-worker about done()
in Jest tests.
He's orders of magnitude more experienced with JavaScript than I am, and I came in after async
/await
was generally accepted, plus came from a .NET environment, so I was used to it.
I write my tests like this:
it("should return 200 OK for POST method", async () => {
await request(app).post("SOMEENDPOINT")
.attach("file", "file")
.expect(200);
});
He's more used to promises so will write his tests like this:
it("should return 200 OK for POST method", (done) => {
request(app).post("SOMEENDPOINT")
.attach("file", "file")
.expect(200, done);
});
He's fine with my push to async
/await
, but insists I have to include done
, such that I'm either doing his version modified version:
it("should return 200 OK for POST method", async (done) => {
await request(app).post("SOMEENDPOINT")
.attach("file", "file")
.expect(200, done);
});
Or:
it("should return 200 OK for POST method", async (done) => {
const res = await request(app).post("SOMEENDPOINT")
.attach("file", "file");
expect(res.status).toBe(200);
done();
});
While I recognize calling done()
is entirely necessary when it's included as a parameter, I was under the impression it is wholly unnecessary when using async
/await
in this context.
Request is supertest.request
.
My question is, do I need to use done
at all with async
/await
?