'How to mock axios.get() with mockRejectedValue
I have a function which does
axios
.get(//URL)
.then((response) => {
return res.json({ /*build response*/ });
})
.catch(function (error) {
return res.status(500).json({ status: error.response.status, error: error.response.data });
}
I am trying to mock the error object in the test
it("returns 500", async () => {
axios.get.mockRejectedValue(new Error({ response: {
status: 500, data: "Internal Server Error" }}));
const resp = await request(app).get("/");
//expect ....
});
This is not working for me, I get thrown: "Exceeded timeout of 5000 ms for a test.. What I am missing here?
It works when I mock a positive response
axios.get.mockResolvedValue({ mockResponse });
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
