Jest is throwing this error Matcher error: received value must be a promise because in expect you are just passing the function reference. Without () – action is just a function reference it will not return anything.
To fix this issue you have to call the function in expect like action() so it will return the promise object.
And the second part, you have to throw error like. Promise.reject(new Error('some error')); in the reject so the tothrow condition can be full filled.
Example:
function hostelService() {
return Promise.reject(new Error('some error'));
}
const action = async () => {
await hostelService();
};
it( "Should throw the error", async () => {
await expect(action()).rejects.toThrow('some error');
});
Hope this will be helpful.