Last active
March 31, 2022 14:05
-
-
Save scottgamer/2a9199510d15ad6b8cc82d9b4a5698b5 to your computer and use it in GitHub Desktop.
mocking modules
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
| const mockedFetch = jest.fn(() => | |
| Promise.resolve({ | |
| json: () => Promise.resolve({}), | |
| }) | |
| ) as jest.Mock; | |
| global.fetch = mockedFetch; | |
| test("Renders the component with posts", async () => { | |
| render(<Posts />); | |
| expect(fetch).toHaveBeenCalledTimes(1); | |
| const postsItems = await screen.findAllByRole("article"); | |
| expect(postsItems).toHaveLength(2); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment