mwg API
    Preparing search index...

    Function fakeFetch

    • A fetch for any HttpTransport client's fetch option: respond answers each request, with a Response or with a plain value sent as a JSON body, and calls records them in order.

      Parameters

      • respond: (url: string, init?: RequestInit) => unknown

      Returns {
          (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
          (input: string | URL | Request, init?: RequestInit): Promise<Response>;
      } & { calls: FakeFetchCall[] }

        • (input: URL | RequestInfo, init?: RequestInit): Promise<Response>
        • Parameters

          • input: URL | RequestInfo
          • Optionalinit: RequestInit

          Returns Promise<Response>

        • (input: string | URL | Request, init?: RequestInit): Promise<Response>
        • Parameters

          • input: string | URL | Request
          • Optionalinit: RequestInit

          Returns Promise<Response>

      import { NewsClient } from '@datamoc/mwg/core';
      import { fakeFetch } from '@datamoc/mwg/testing';

      const fetch = fakeFetch(() => [{ id: '1', title: 'Patch notes', body: 'Fixed things.' }]);
      const news = new NewsClient({ endpoint: 'https://example.test/news', fetch });