I am learning unit testing. I wanted to mock the database response from the controller. How can I do that? here is my code:
imageController.ts
const getImages = async (req: Request, res: Response) => {
const images = await Image.find({}).sort({ date: -1 });
return res.status(200).json(images);
};
image.test.ts
describe("It shuld be get methoad", () => {
test("get all image url", async () => {
const res = await request(app).get("/api/v1/all");
expect(res.statusCode).toBe(200);
// console.log(res.body);
let images = res.body
// expect(images.length).toBeGreaterThan(0);
});
});