jest-fetch-mock

  • Version 3.0.3
  • Published
  • 104 kB
  • 2 dependencies
  • MIT license

Install

npm i jest-fetch-mock
yarn add jest-fetch-mock
pnpm add jest-fetch-mock

Overview

fetch mock for jest

Index

Variables

variable fetchMock

const fetchMock: FetchMock;

    Functions

    function disableFetchMocks

    disableFetchMocks: () => void;

      function enableFetchMocks

      enableFetchMocks: () => void;

        Interfaces

        interface FetchMock

        interface FetchMock
        extends jest.MockInstance<
        Promise<Response>,
        [string | Request | undefined, RequestInit | undefined]
        > {}

          method disableMocks

          disableMocks: () => void;

            method doMock

            doMock: {
            (fn?: MockResponseInitFunction): FetchMock;
            (response: string, responseInit?: MockParams): FetchMock;
            };

              method doMockIf

              doMockIf: {
              (urlOrPredicate: UrlOrPredicate, fn?: MockResponseInitFunction): FetchMock;
              (
              urlOrPredicate: UrlOrPredicate,
              response: string,
              responseInit?: MockParams
              ): FetchMock;
              };

                method doMockOnce

                doMockOnce: {
                (fn?: MockResponseInitFunction): FetchMock;
                (response: string, responseInit?: MockParams): FetchMock;
                };

                  method doMockOnceIf

                  doMockOnceIf: {
                  (urlOrPredicate: UrlOrPredicate, fn?: MockResponseInitFunction): FetchMock;
                  (
                  urlOrPredicate: UrlOrPredicate,
                  response: string,
                  responseInit?: MockParams
                  ): FetchMock;
                  };

                    method dontMock

                    dontMock: {
                    (fn?: MockResponseInitFunction): FetchMock;
                    (response: string, responseInit?: MockParams): FetchMock;
                    };

                      method dontMockIf

                      dontMockIf: {
                      (urlOrPredicate: UrlOrPredicate, fn?: MockResponseInitFunction): FetchMock;
                      (
                      urlOrPredicate: UrlOrPredicate,
                      response: string,
                      responseInit?: MockParams
                      ): FetchMock;
                      };

                        method dontMockOnce

                        dontMockOnce: {
                        (fn?: MockResponseInitFunction): FetchMock;
                        (response: string, responseInit?: MockParams): FetchMock;
                        };

                          method dontMockOnceIf

                          dontMockOnceIf: {
                          (urlOrPredicate: UrlOrPredicate, fn?: MockResponseInitFunction): FetchMock;
                          (
                          urlOrPredicate: UrlOrPredicate,
                          response: string,
                          responseInit?: MockParams
                          ): FetchMock;
                          };

                            method enableMocks

                            enableMocks: () => void;

                              method isMocking

                              isMocking: (input: string | Request) => boolean;

                                method mockAbort

                                mockAbort: () => FetchMock;

                                  method mockAbortOnce

                                  mockAbortOnce: () => FetchMock;

                                    method mockIf

                                    mockIf: {
                                    (urlOrPredicate: UrlOrPredicate, fn?: MockResponseInitFunction): FetchMock;
                                    (
                                    urlOrPredicate: UrlOrPredicate,
                                    response: string,
                                    responseInit?: MockParams
                                    ): FetchMock;
                                    };

                                      method mockOnce

                                      mockOnce: {
                                      (fn?: MockResponseInitFunction): FetchMock;
                                      (response: string, responseInit?: MockParams): FetchMock;
                                      };

                                        method mockOnceIf

                                        mockOnceIf: {
                                        (urlOrPredicate: UrlOrPredicate, fn?: MockResponseInitFunction): FetchMock;
                                        (
                                        urlOrPredicate: UrlOrPredicate,
                                        response: string,
                                        responseInit?: MockParams
                                        ): FetchMock;
                                        };

                                          method mockReject

                                          mockReject: (error?: ErrorOrFunction) => FetchMock;

                                            method mockRejectOnce

                                            mockRejectOnce: (error?: ErrorOrFunction) => FetchMock;

                                              method mockResponse

                                              mockResponse: {
                                              (fn: MockResponseInitFunction): FetchMock;
                                              (response: string, responseInit?: MockParams): FetchMock;
                                              };

                                                method mockResponseOnce

                                                mockResponseOnce: {
                                                (fn: MockResponseInitFunction): FetchMock;
                                                (response: string, responseInit?: MockParams): FetchMock;
                                                };

                                                  method mockResponses

                                                  mockResponses: (
                                                  ...responses: Array<string | [string, MockParams] | MockResponseInitFunction>
                                                  ) => FetchMock;

                                                    method once

                                                    once: {
                                                    (fn: MockResponseInitFunction): FetchMock;
                                                    (url: string, responseInit?: MockParams): FetchMock;
                                                    };

                                                      method resetMocks

                                                      resetMocks: () => void;

                                                        call signature

                                                        (input?: string | Request, init?: RequestInit): Promise<Response>;

                                                          interface GlobalWithFetchMock

                                                          interface GlobalWithFetchMock extends Global {}

                                                            property fetch

                                                            fetch: FetchMock;

                                                              property fetchMock

                                                              fetchMock: FetchMock;

                                                                interface MockParams

                                                                interface MockParams {}

                                                                  property headers

                                                                  headers?: string[][] | { [key: string]: string };

                                                                    property status

                                                                    status?: number;

                                                                      property statusText

                                                                      statusText?: string;

                                                                        property url

                                                                        url?: string;

                                                                          interface MockResponseInit

                                                                          interface MockResponseInit extends MockParams {}

                                                                            property body

                                                                            body?: string;

                                                                              property init

                                                                              init?: MockParams;

                                                                                Type Aliases

                                                                                type ErrorOrFunction

                                                                                type ErrorOrFunction = Error | ((...args: any[]) => Promise<any>);

                                                                                  type MockResponseInitFunction

                                                                                  type MockResponseInitFunction = (
                                                                                  request: Request
                                                                                  ) => Promise<MockResponseInit | string>;

                                                                                    type UrlOrPredicate

                                                                                    type UrlOrPredicate = string | RegExp | ((input: Request) => boolean);

                                                                                      Namespaces

                                                                                      namespace global

                                                                                      namespace global {}

                                                                                        variable fetchMock

                                                                                        const fetchMock: FetchMock;

                                                                                          namespace global.NodeJS

                                                                                          namespace global.NodeJS {}

                                                                                            interface Global

                                                                                            interface Global {}

                                                                                              property fetch

                                                                                              fetch: FetchMock;

                                                                                                Package Files (1)

                                                                                                Dependencies (2)

                                                                                                Dev Dependencies (7)

                                                                                                Peer Dependencies (0)

                                                                                                No peer dependencies.

                                                                                                Badge

                                                                                                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/jest-fetch-mock.

                                                                                                • Markdown
                                                                                                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/jest-fetch-mock)
                                                                                                • HTML
                                                                                                  <a href="https://www.jsdocs.io/package/jest-fetch-mock"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>