Created
June 13, 2020 14:13
-
-
Save Dromediansk/8bffa37b1f000b18e1d093adad04887f to your computer and use it in GitHub Desktop.
Handling errors in useFetch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it("should catch error", async () => { | |
jest.spyOn(global, "fetch").mockImplementation(() => | |
Promise.resolve({ | |
json: () => Promise.reject("oops, error occured!"), | |
}) | |
); | |
const { result, waitForNextUpdate } = renderHook(() => | |
useFetch(stubbedFetchUrl, { current: true }, []) | |
); | |
await waitForNextUpdate(); | |
expect(result.current).toStrictEqual({ | |
loading: false, | |
data: [], | |
error: "oops, error occured!", | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment