5.0.0 • Published 9 months ago

parrot-fetch v5.0.0

Weekly downloads
10
License
Apache-2.0
Repository
github
Last release
9 months ago

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');
5.0.0

9 months ago

5.0.0-alpha.1

2 years ago

5.0.0-alpha.0

3 years ago

4.1.1

4 years ago

4.1.0

4 years ago

4.0.1

4 years ago

3.1.0

6 years ago

3.0.0

6 years ago