Skip to content

Instantly share code, notes, and snippets.

@scottgamer
Last active March 31, 2022 14:05
Show Gist options
  • Select an option

  • Save scottgamer/2a9199510d15ad6b8cc82d9b4a5698b5 to your computer and use it in GitHub Desktop.

Select an option

Save scottgamer/2a9199510d15ad6b8cc82d9b4a5698b5 to your computer and use it in GitHub Desktop.
mocking modules
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