🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

parrot-fetch

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parrot-fetch

A Fetch mocking implementation of Parrot.

5.3.0
latest
Source
npm
Version published
Weekly downloads
27
2600%
Maintainers
0
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 03 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts