Last active
June 13, 2020 13:53
-
-
Save Dromediansk/967f068c0f7824be2ad8b00ab4533f93 to your computer and use it in GitHub Desktop.
Getting data test in useFetch.test.js
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 return data after fetch", async () => { | |
// Mock API | |
jest.spyOn(global, "fetch").mockImplementation(() => | |
Promise.resolve({ | |
json: () => Promise.resolve(stubbedCountries), | |
}) | |
); | |
// Execute | |
const { result, waitForNextUpdate } = renderHook(() => | |
useFetch(stubbedFetchUrl, { current: true }, []) | |
); | |
await waitForNextUpdate(); | |
// Assert | |
expect(result.current).toStrictEqual({ | |
loading: false, | |
data: stubbedCountries, | |
error: null, | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment