Skip to content

Instantly share code, notes, and snippets.

@guilhermepontes
Created January 9, 2017 22:25
Show Gist options
  • Save guilhermepontes/e055590c94e614b19a28ce047d7c5633 to your computer and use it in GitHub Desktop.
Save guilhermepontes/e055590c94e614b19a28ce047d7c5633 to your computer and use it in GitHub Desktop.
whatwg-fetch mocks
const fetchMock = (response) => {
window.fetch = jest.fn().mockImplementation(() =>
new Promise((resolve) => {
resolve({ json: () => response })
})
)
}
const fetchMockRejected = (response) => {
window.fetch = jest.fn().mockImplementation(() =>
Promise.reject(response)
)
}
export {
fetchMock,
fetchMockRejected
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment