Skip to content

Instantly share code, notes, and snippets.

@AlanGreene
Created August 21, 2019 23:56
Show Gist options
  • Save AlanGreene/5d38df65c82b52de79cc0f55454afa15 to your computer and use it in GitHub Desktop.
Save AlanGreene/5d38df65c82b52de79cc0f55454afa15 to your computer and use it in GitHub Desktop.
jest - detect unmocked network requests
// 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