Last active
June 1, 2019 13:00
-
-
Save ivan-ha/ec7ed5aa1c262cd0f7bce6f8a5471c30 to your computer and use it in GitHub Desktop.
react-hooks-test-custom-hooks
This file contains hidden or 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
import { renderHook, act } from "react-hooks-testing-library"; | |
jest.mock("axios"); | |
describe("useRandomUsers", () => { | |
it("call API and return results", async () => { | |
axios.mockImplementation(() => Promise.resolve({ data: mockResponse })); | |
const { result, waitForNextUpdate } = renderHook(() => useRandomUsers()); | |
expect(result.current).toStrictEqual([]); | |
await waitForNextUpdate(); | |
expect(result.current).toStrictEqual(mockResponse.results); | |
expect(axios).toHaveBeenCalledWith( | |
"https://randomuser.me/api/?results=10&inc=name,login&nat=us" | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment