parrot-fetch

5.0.0 • Public • Published

Parrot-Fetch

parrot-fetch is an implementation of Parrot that mocks the Fetch API.

Example

import parrotFetch from 'parrot-fetch';
import scenarios from './scenarios';

// fetch will be mocked once the parrotFetch function is called
const parrot = parrotFetch(scenarios);

// set the scenario to be used
parrot.setActiveScenario('has a ship log');

Mocking a non-global fetch example

import parrotFetch from 'parrot-fetch';
import scenarios from './scenarios';

// include a fetchClient inside of a fetchWrapper object and pass it into the parrotFetch function to mock the fetchClient

const fetchWrapper = {
  fetchClient,
};
const parrot = parrotFetch(scenarios, fetchWrapper);

// set the scenario to be used
parrot.setActiveScenario('has a ship log');

Mocking a non-global fetch - use case example

An example use case for mocking a non-global fetch could be mocking a fetchClient that is passed in as an extra thunk argument using redux-thunk withExtraArgument. Mocking this redux thunk fetchClient would look something like below:

import parrotFetch from 'parrot-fetch';
import scenarios from './scenarios';

const callParrotFetch = () => {
  return (dispatch, getState, fetchWrapper) => {
    // fetchWrapper = { fetchClient };
    return parrotFetch(scenarios, fetchWrapper);
  };
};
const parrot = dispatch(callParrotFetch());
parrot.setActiveScenario('has a ship log');

Readme

Keywords

none

Package Sidebar

Install

npm i parrot-fetch

Weekly Downloads

0

Version

5.0.0

License

Apache-2.0

Unpacked Size

22 kB

Total Files

5

Last publish

Collaborators

  • jayjaycross
  • amexopensource