Created
January 9, 2017 22:25
-
-
Save guilhermepontes/e055590c94e614b19a28ce047d7c5633 to your computer and use it in GitHub Desktop.
whatwg-fetch mocks
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 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