Skip to content

starsprung/farfetched

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

farfetched

This is a simple library for mocking responses (like Mockjax) for window.fetch. I recommend using GitHub's fetch polyfill.

I'm going to start simple and add methods and features as I need them or they're requested.

Installation

Farfetched is made to work with Browserify. Install it:

$ npm install --save-dev farfetched

Then, require it in your project and attach it to window:

var farfetched = require("farfetched");
farfetched.attach(window);

API

farfetched(url, options)

Creates a handler and returns its ID.

url is the URL (either a String or Regexp) to match and mock.

options is an object and can have the following properties:

  • response

    The response to return or a function that can be called to obtain it.

farfetched.attach(window)

Attaches farfetched to the global scope, replacing window.fetch. window.fetch is still used when farfetched can't find a handler that matches a route.

farfetched.clear(id)

Clears the handler with the given ID.

About

Response mocking for window.fetch

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%