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

vi-fetch

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vi-fetch

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.6K
decreased by-16.18%
Maintainers
1
Weekly downloads
 
Created
Source

vi-fetch

An easy way to mock fetch

Compatible with Jest and Vitest.

Installing

# with npm
npm install -D vi-fetch

# with pnpm
pnpm install -D vi-fetch

# with yarn
yarn install -D vi-fetch

Usage

Setup

Before using mock API, you need to set up fetch mock. To do this, import vi-fetch/setup in your setup file:

import 'vi-fetch/setup';

If fetch is located on another object, you can manually setup it with prepareFetch function, imported from vi-fetch:

import { prepareFetch } from 'vi-fetch';

prepareFetch(globalThis, 'fetchNode');

Mock API

import { mockApi } from 'vi-fetch';

const mock = mockApi('GET', '/apples').willResolve(33);

expect(mock).toCallApi();

Aliases for popular methods are available: mockGet, mockPost, mockPut, mockPatch, mockDelete.

You can define baseUrl globally:

import { mockApi } from 'vi-fetch';

mockApi.setOptions({
  baseUrl: 'https://api.com/v1',
});

You can create isolated mockApi:

import { createMockApi } from 'vi-fetch';

const { mockApi } = createMockApi({ baseUrl: 'http://api.com/v2' });

const mock = mockApi('GET', '/apples').willResolve(33);

expect(mock).toCallApi();

FAQs

Package last updated on 02 Jan 2022

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