fetch-mock

  • Version 12.5.3
  • Published
  • 153 kB
  • 4 dependencies
  • MIT license

Install

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

Overview

Mock http requests made using fetch

Index

Variables

variable defaultFetchMockConfig

const defaultFetchMockConfig: FetchMockConfig;

    variable fetchMock

    const fetchMock: FetchMock;

      Classes

      class FetchMock

      class FetchMock {}

        constructor

        constructor(config: FetchMockConfig, router?: Router);

          property any

          any: (
          this: FetchMock,
          response: RouteResponse,
          options?: UserRouteConfig | string
          ) => FetchMock;

            property anyOnce

            anyOnce: (
            this: FetchMock,
            response: RouteResponse,
            options?: UserRouteConfig | string
            ) => FetchMock;

              property callHistory

              callHistory: CallHistory;

                property config

                config: FetchMockConfig;

                  property delete

                  delete: {
                  (this: FetchMock, matcher: UserRouteConfig | RouteConfigWrapper): FetchMock;
                  (
                  this: FetchMock,
                  matcher: RouteMatcher,
                  response: RouteResponse,
                  options?: UserRouteConfig | string
                  ): FetchMock;
                  };

                    property deleteOnce

                    deleteOnce: {
                    (this: FetchMock, matcher: UserRouteConfig | RouteConfigWrapper): FetchMock;
                    (
                    this: FetchMock,
                    matcher: RouteMatcher,
                    response: RouteResponse,
                    options?: UserRouteConfig | string
                    ): FetchMock;
                    };

                      property get

                      get: {
                      (this: FetchMock, matcher: UserRouteConfig | RouteConfigWrapper): FetchMock;
                      (
                      this: FetchMock,
                      matcher: RouteMatcher,
                      response: RouteResponse,
                      options?: UserRouteConfig | string
                      ): FetchMock;
                      };

                        property getOnce

                        getOnce: {
                        (this: FetchMock, matcher: UserRouteConfig | RouteConfigWrapper): FetchMock;
                        (
                        this: FetchMock,
                        matcher: RouteMatcher,
                        response: RouteResponse,
                        options?: UserRouteConfig | string
                        ): FetchMock;
                        };

                          property head

                          head: {
                          (this: FetchMock, matcher: UserRouteConfig | RouteConfigWrapper): FetchMock;
                          (
                          this: FetchMock,
                          matcher: RouteMatcher,
                          response: RouteResponse,
                          options?: UserRouteConfig | string
                          ): FetchMock;
                          };

                            property headOnce

                            headOnce: {
                            (this: FetchMock, matcher: UserRouteConfig | RouteConfigWrapper): FetchMock;
                            (
                            this: FetchMock,
                            matcher: RouteMatcher,
                            response: RouteResponse,
                            options?: UserRouteConfig | string
                            ): FetchMock;
                            };

                              property once

                              once: {
                              (this: FetchMock, matcher: UserRouteConfig | RouteConfigWrapper): FetchMock;
                              (
                              this: FetchMock,
                              matcher: RouteMatcher,
                              response: RouteResponse,
                              options?: UserRouteConfig | string
                              ): FetchMock;
                              };

                                property patch

                                patch: {
                                (this: FetchMock, matcher: UserRouteConfig | RouteConfigWrapper): FetchMock;
                                (
                                this: FetchMock,
                                matcher: RouteMatcher,
                                response: RouteResponse,
                                options?: UserRouteConfig | string
                                ): FetchMock;
                                };

                                  property patchOnce

                                  patchOnce: {
                                  (this: FetchMock, matcher: UserRouteConfig | RouteConfigWrapper): FetchMock;
                                  (
                                  this: FetchMock,
                                  matcher: RouteMatcher,
                                  response: RouteResponse,
                                  options?: UserRouteConfig | string
                                  ): FetchMock;
                                  };

                                    property post

                                    post: {
                                    (this: FetchMock, matcher: UserRouteConfig | RouteConfigWrapper): FetchMock;
                                    (
                                    this: FetchMock,
                                    matcher: RouteMatcher,
                                    response: RouteResponse,
                                    options?: UserRouteConfig | string
                                    ): FetchMock;
                                    };

                                      property postOnce

                                      postOnce: {
                                      (this: FetchMock, matcher: UserRouteConfig | RouteConfigWrapper): FetchMock;
                                      (
                                      this: FetchMock,
                                      matcher: RouteMatcher,
                                      response: RouteResponse,
                                      options?: UserRouteConfig | string
                                      ): FetchMock;
                                      };

                                        property put

                                        put: {
                                        (this: FetchMock, matcher: UserRouteConfig | RouteConfigWrapper): FetchMock;
                                        (
                                        this: FetchMock,
                                        matcher: RouteMatcher,
                                        response: RouteResponse,
                                        options?: UserRouteConfig | string
                                        ): FetchMock;
                                        };

                                          property putOnce

                                          putOnce: {
                                          (this: FetchMock, matcher: UserRouteConfig | RouteConfigWrapper): FetchMock;
                                          (
                                          this: FetchMock,
                                          matcher: RouteMatcher,
                                          response: RouteResponse,
                                          options?: UserRouteConfig | string
                                          ): FetchMock;
                                          };

                                            property router

                                            router: Router;

                                              property sticky

                                              sticky: {
                                              (this: FetchMock, matcher: UserRouteConfig | RouteConfigWrapper): FetchMock;
                                              (
                                              this: FetchMock,
                                              matcher: RouteMatcher,
                                              response: RouteResponse,
                                              options?: UserRouteConfig | string
                                              ): FetchMock;
                                              };

                                                method catch

                                                catch: (response?: RouteResponse) => FetchMock;

                                                  method clearHistory

                                                  clearHistory: () => FetchMock;

                                                    method createInstance

                                                    createInstance: () => FetchMock;

                                                      method defineMatcher

                                                      defineMatcher: (matcher: MatcherDefinition) => void;

                                                        method fetchHandler

                                                        fetchHandler: (
                                                        this: FetchMock,
                                                        requestInput: string | URL | Request,
                                                        requestInit?: RequestInit
                                                        ) => Promise<Response>;

                                                          method hardReset

                                                          hardReset: (options?: HardResetOptions) => FetchMock;

                                                            method mockGlobal

                                                            mockGlobal: (this: FetchMock) => FetchMock;

                                                              method modifyRoute

                                                              modifyRoute: (routeName: string, options: ModifyRouteConfig) => this;

                                                                method removeRoute

                                                                removeRoute: (routeName: string) => FetchMock;

                                                                  method removeRoutes

                                                                  removeRoutes: (options?: RemoveRouteOptions) => FetchMock;

                                                                    method route

                                                                    route: {
                                                                    (matcher: UserRouteConfig | RouteConfigWrapper): FetchMock;
                                                                    (
                                                                    matcher: RouteMatcher,
                                                                    response: RouteResponse,
                                                                    options?: string | UserRouteConfig | RouteConfigWrapper
                                                                    ): FetchMock;
                                                                    };

                                                                      method spy

                                                                      spy: (
                                                                      this: FetchMock,
                                                                      matcher?: RouteMatcher | UserRouteConfig | RouteConfigWrapper,
                                                                      name?: RouteName
                                                                      ) => FetchMock;

                                                                        method spyGlobal

                                                                        spyGlobal: (this: FetchMock) => FetchMock;

                                                                          method unmockGlobal

                                                                          unmockGlobal: (this: FetchMock) => FetchMock;

                                                                            class RouteConfigWrapper

                                                                            class RouteConfigWrapper implements UserRouteConfig {}

                                                                              constructor

                                                                              constructor(config: UserRouteConfig);

                                                                                Type Aliases

                                                                                type CallHistoryFilter

                                                                                type CallHistoryFilter = RouteName | Matched | Unmatched | boolean | RouteMatcher;

                                                                                  type CallLog

                                                                                  type CallLog = {
                                                                                  args: unknown[];
                                                                                  url: string;
                                                                                  options: NormalizedRequestOptions;
                                                                                  request?: Request;
                                                                                  signal?: AbortSignal;
                                                                                  route?: Route;
                                                                                  response?: Response;
                                                                                  expressParams?: {
                                                                                  [x: string]: string;
                                                                                  };
                                                                                  queryParams?: URLSearchParams;
                                                                                  pendingPromises: Promise<unknown>[];
                                                                                  };

                                                                                    type FetchMockConfig

                                                                                    type FetchMockConfig = FetchMockGlobalConfig & FetchImplementations;

                                                                                      type MatcherDefinition

                                                                                      type MatcherDefinition = {
                                                                                      name: string;
                                                                                      matcher: MatcherGenerator;
                                                                                      usesBody?: boolean;
                                                                                      };

                                                                                        type ModifyRouteConfig

                                                                                        type ModifyRouteConfig = Omit<Nullable<UserRouteSpecificConfig>, 'name' | 'sticky'>;

                                                                                          type RemoveRouteOptions

                                                                                          type RemoveRouteOptions = {
                                                                                          includeSticky?: boolean;
                                                                                          includeFallback?: boolean;
                                                                                          names?: string[];
                                                                                          };

                                                                                            type RouteMatcher

                                                                                            type RouteMatcher = RouteMatcherUrl | RouteMatcherFunction;

                                                                                              type RouteName

                                                                                              type RouteName = string;

                                                                                                type RouteResponse

                                                                                                type RouteResponse =
                                                                                                | RouteResponseData
                                                                                                | RouteResponsePromise
                                                                                                | RouteResponseFunction;

                                                                                                  type UserRouteConfig

                                                                                                  type UserRouteConfig = UserRouteSpecificConfig & FetchMockGlobalConfig;

                                                                                                    Package Files (6)

                                                                                                    Dependencies (4)

                                                                                                    Dev Dependencies (0)

                                                                                                    No dev dependencies.

                                                                                                    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/fetch-mock.

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