Skip to content

Instantly share code, notes, and snippets.

@offirgolan
Last active January 30, 2019 18:37
Show Gist options
  • Save offirgolan/94503d60563512de8b3d6783ceafe798 to your computer and use it in GitHub Desktop.
Save offirgolan/94503d60563512de8b3d6783ceafe798 to your computer and use it in GitHub Desktop.
/*
Create a new polly instance.
Connect Polly to fetch. By default, it will record any requests that it
hasn't yet seen while replaying ones it has already recorded.
*/
const polly = new Polly('Simple Example', {
adapters: ['fetch'], // Hook into `fetch`
persister: 'local-storage', // Read/write to/from local-storage
});
/* Any networks requests here using fetch will be handled by the Polly instance. */
await fetch('/posts/1');
/* Calling `stop` will persist requests as well as disconnect from any connected adapters. */
await polly.stop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment