Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parrot-fetch

Package Overview
Dependencies
Maintainers
2
Versions
12
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.

  • 4.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
2
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 17 Apr 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc