Skip to content

Instantly share code, notes, and snippets.

@Dromediansk
Created June 11, 2020 05:14
Show Gist options
  • Save Dromediansk/772c4a388433154173ee0a7c57b83c93 to your computer and use it in GitHub Desktop.
Save Dromediansk/772c4a388433154173ee0a7c57b83c93 to your computer and use it in GitHub Desktop.
Fetching data error
it("should catch error", async () => {
// Mock API
jest.spyOn(global, "fetch").mockImplementation(() =>
Promise.resolve({
json: () =>
Promise.resolve({
status: 500,
}),
})
);
const result = await getAllCountries();
expect(result.status).toBe(500);
expect(result.data).not.toBeDefined();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment