I'm testing a sign-in controller and therefore I've written the following test:
it("return 200 when user signed in successfully", async () => {
await request(app)
.post("/api/v1/signup")
.send({
name: "some-name",
email: "test@mail.com",
password: "abcdefg",
})
.expect(StatusCodes.CREATED);
await request(app).post("/api/v1/signin")
.send({
name: "some-name",
email: "test@mail.com",
password: "abcdefg",
});
.expect(StatusCodes.OK);
});
The test code is straightforward. When the two controllers are tested in postman, everything work well and when start to test in jest, I receive bad request when a user try to sign in. The reason for this bad request is because when try to find an user by email in the signin controller
, I receive null which I really don't understand what is the cause of this result.
What I must take into account to resolve this issue when testing in jest?