I want to mock the returned value in the catch block of an async function with Jest
This is the function I am writing the unit test for:
try {
make some axios request
}
return users;
} catch (err) {
return new Map();
}
};
it('should catch error when query is unsuccessful', async () => {
axios.get.mockRejectedValue(new Map());
const res = getUserDataByIds('someUserIds');
await expect(res).rejects.toThrow();
});
I am getting the error from Jest:
expect(received).rejects.toEqual()
Received promise resolved instead of rejected
Resolved to value: Map {}
I expect that the test should pass because I'm mocking a rejected value.