Skip to content

Instantly share code, notes, and snippets.

@qrohlf
Created May 10, 2016 18:53
Show Gist options
  • Save qrohlf/478310964d4280c0cfb9c4e1ac06a74f to your computer and use it in GitHub Desktop.
Save qrohlf/478310964d4280c0cfb9c4e1ac06a74f to your computer and use it in GitHub Desktop.
// Make fetch evil - useful for testing retry logic
// MAKE FETCH EVIL - THIS SHOULD NOT BE IN THE FINAL COMMIT
const _fetch = window.fetch
const evilFetch = function () {
const r = Math.random()
if (r < 0.5) {
return _fetch.apply(null, arguments)
} else if (r < 0.75) {
console.warn('mocking fetch with TypeError')
return Promise.reject(new TypeError('blarg'))
} else {
console.warn('mocking fetch with 404')
return _fetch('/this/will/404')
}
}
window.fetch = evilFetch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment