Created
August 21, 2019 23:56
-
-
Save AlanGreene/5d38df65c82b52de79cc0f55454afa15 to your computer and use it in GitHub Desktop.
jest - detect unmocked network requests
This file contains 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
// from @kentcdodds | |
beforeEach(() => { | |
jest.spyOn(window, 'fetch').mockImplementation((...args) => { | |
console.warn('window.fetch is not mocked for this call', ...args); | |
throw new Error('This must be mocked!'); | |
}); | |
}); | |
afterEach(() => { | |
window.fetch.mockRestore(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment