I am writing test for useFetchData hook and in this function I am firing toast in catch block. How can I actually check if ToastComponent was mounted/toast function was fired. I tried using spyOn on toast but it is saying that it is not a function actually. Any other guesses?
test("should not return any data", async () => {
jest.spyOn(global, "fetch").mockImplementation(() => {
return Promise.resolve({
json: () => Promise.reject("oopss"),
});
});
const { result, waitForNextUpdate } = renderHook(() =>
useFetchData("lorem")
);
await waitForNextUpdate();
expect(result.current).toMatchObject({
countries: undefined,
loading: false,
});