I recently ran into the following testing code in an Express app using Supertest and Jest:
const supertest = require("supertest");
const app = require("../app");
const api = supertest(app);
test("notes are returned as json", async () => {
await api
.get("/api/notes")
.expect(200)
.expect("Content-Type", /application\/json/);
});
I'm kind of confused where the .expect(200)
is coming from. Is this part of Supertest? Because I know that in Jest when we call expect
we typically use a matcher like this:
expect(200).toBe(200)
But somehow this test works without having to call a matcher.