Skip to content

Instantly share code, notes, and snippets.

@amoHoban
amoHoban / mockFetch.js
Created March 7, 2019 12:34
mock fetch calls, overriding the response (e.g. Server down during development)
// e.g. mockFetch({'avengers/me': {'name': "iron man", 'rank': 2}})
function mockFetch(urlResponseMap) {
window.fetchOriginal = window.fetch
window.fetch = (...params) => {
const lookFor = Object.keys(urlResponseMap);
const url = typeof params[0] == 'object' ? params[0].url : params[0];