How to use the fetch-mock.config function in fetch-mock

To help you get started, we’ve selected a few fetch-mock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vacuumlabs / adalite / test / mock.js View on Github external
function mockTransactionSubmitter() {
    fetchMock.config.overwriteRoutes = true

    const requestsAndResponses = {
      '{"txHash":"73131c773879e7e634022f8e0175399b7e7814c42684377cf6f8c7a1adb23112","txBody":"82839f8200d81858248258206ca5fde47f4ff7f256a7464dbf0cb9b4fb6bce9049eee1067eed65cf5d6e2765008200d81858248258206ca5fde47f4ff7f256a7464dbf0cb9b4fb6bce9049eee1067eed65cf5d6e276501ff9f8282d818584283581c13f3997560a5b81f5ac680b3322a2339433424e4e589ab3d752afdb6a101581e581c2eab4601bfe583febc23a04fb0abc21557adb47cea49c68d7b2f40a5001ac63884bf182f8282d818584283581cab41e66f954dd7f1c16081755eb02ee61dc720bd9e05790f9de649b7a101581e581c140539c64edded60a7f2d169cb4da86a47bccc6a92e4130754fd0f36001a306ccb8f1a002a8c6cffa0828200d81858858258406830165e81b0666850f36a4583f7a8a29b09e120f99852c56d37ded39bed1bb0464a98c35cf0f6458be6351d8f8527fb8b17fe6be0523e901d9562c2b7a52a9e5840951e97f421d44345f260f5d84070c93a0dbc7dfa883a2cbedb1cedee22cb86b459450d615d580d9a3bd49cf09f2848447287cf306f09115d831276cac42919088200d81858858258400093f68540416f4deea889da21af1f1760edc3478bcac204a3013a046327c29c1748af9d186a7e463caa63ef2c660e5f2a051ad014a050d1b27e636128e1947e5840f44da425f699c39ca539c6e2e2262ed4a4b977dd8bdbb4450d40ab7503dc9b4ebca68a8f819d1f92bfdd2af2825b26bb07ef1f586c1135a88b1cdc8520142208"}': {
        result: true,
      },
    }
    // eslint-disable-next-line guard-for-in
    for (const request in requestsAndResponses) {
      fetchMock.mock({
        // eslint-disable-next-line no-loop-func
        matcher: (url, opts) => {
          return (
            url === CARDANOLITE_CONFIG.CARDANOLITE_TRANSACTION_SUBMITTER_URL &&
            opts &&
            opts.body === request
          )
github google / skia-buildbot / ct / modules / admin-tasks-sk / admin-tasks-sk-demo.ts View on Github external
import './index';
import '../../../infra-sk/modules/theme-chooser-sk';
import { $$ } from 'common-sk/modules/dom';
import fetchMock from 'fetch-mock';
import { pageSets } from '../pageset-selector-sk/test_data';
import 'elements-sk/error-toast-sk';

fetchMock.config.overwriteRoutes = false;
fetchMock.post('begin:/_/page_sets/', pageSets);
// For determining running tasks for the user we just say 2.
fetchMock.postOnce('begin:/_/get', {
  data: [], ids: [], pagination: { offset: 0, size: 1, total: 2 }, permissions: [],
});
fetchMock.post('begin:/_/get', {
  data: [], ids: [], pagination: { offset: 0, size: 1, total: 0 }, permissions: [],
});

const chromiumPerf = document.createElement('admin-tasks-sk');
($$('#container') as HTMLElement).appendChild(chromiumPerf);
github americanexpress / iguazu-graphql / __tests__ / executeFetch.spec.js View on Github external
describe('executeFetch', () => {
  fetchMock.config.overwriteRoutes = true;

  beforeEach(() => {
    fetchMock.reset();
    delete config.defaultOpts;
  });

  it('is a function', () => expect(executeFetch).toBeInstanceOf(Function));

  it('returns a function', () => expect(executeFetch({})).toBeInstanceOf(Function));

  it('sends a network request using a provided fetchClient by redux thunk', () => {
    expect.assertions(3);
    const fakeEnhancedFetch = jest.fn();
    config.baseFetch.mockClear();
    const dispatch = jest.fn((v) => v);
    const getState = jest.fn(() => ({ name: 'sample-endpoint' }));
github zerkalica / zerollup / packages / wait-all-async / __tests__ / fetchHelper.ts View on Github external
export function setupBrowser(window: any) {
    const keys = Object.keys(fetchMock.config) as (keyof typeof fetchMock.config)[]

    for (let key of keys) {
        if (window[key]) fetchMock.config[key] = window[key]
    }
}
github zerkalica / zerollup / packages / wait-all-async / __tests__ / fetchHelper.ts View on Github external
export function setupBrowser(window: any) {
    const keys = Object.keys(fetchMock.config) as (keyof typeof fetchMock.config)[]

    for (let key of keys) {
        if (window[key]) fetchMock.config[key] = window[key]
    }
}
github vacuumlabs / adalite / test / all.js View on Github external
function mockBlockChainExplorer() {
  fetchMock.config.overwriteRoutes = true;

  var addressesAndResponses = {
    "DdzFFzCqrht4XR8CKm4dPXikMyaSt6Y4iPvEwGYW7GYDgXyVHBbvRvGhzzEQT5XvZ3zVCJR7VB15PbVBzKeabPHruC3JvcFjFV8CynEG" : {"Right":{"caAddress":"DdzFFzCqrht4XR8CKm4dPXikMyaSt6Y4iPvEwGYW7GYDgXyVHBbvRvGhzzEQT5XvZ3zVCJR7VB15PbVBzKeabPHruC3JvcFjFV8CynEG","caType":"CPubKeyAddress","caTxNum":0,"caBalance":{"getCoin":"0"},"caTxList":[]}},
    "DdzFFzCqrht6dzaKMAgFmnkAiyDrdppXw9Pchpf5xofYxgogZTAETLCai7xFwWALmt1vZbwmF2oawDeapBYgkaECcZzYvUmHujuqTiAf" : {"Right":{"caAddress":"DdzFFzCqrht6dzaKMAgFmnkAiyDrdppXw9Pchpf5xofYxgogZTAETLCai7xFwWALmt1vZbwmF2oawDeapBYgkaECcZzYvUmHujuqTiAf","caType":"CPubKeyAddress","caTxNum":0,"caBalance":{"getCoin":"0"},"caTxList":[]}},
    "DdzFFzCqrht7AoRnNfdGquuiSppnRkN1Ywb1EWH5AKgJbxN2e73y7mZTuY2ayf1qCWrvg8pp38qEDcsbxiAAB3XWzYqnQnohKJXNW8xC" : {"Right":{"caAddress":"DdzFFzCqrht7AoRnNfdGquuiSppnRkN1Ywb1EWH5AKgJbxN2e73y7mZTuY2ayf1qCWrvg8pp38qEDcsbxiAAB3XWzYqnQnohKJXNW8xC","caType":"CPubKeyAddress","caTxNum":0,"caBalance":{"getCoin":"0"},"caTxList":[]}},
    "DdzFFzCqrhspk8W7hHE2DnTroA1jdi5iWTQWNHThdrCr14UxTikuKic6M36FdEGhAjVsuoJfvDbsvXnsWPuuPbuzV9542P5usS1qrabS" : {"Right":{"caAddress":"DdzFFzCqrhspk8W7hHE2DnTroA1jdi5iWTQWNHThdrCr14UxTikuKic6M36FdEGhAjVsuoJfvDbsvXnsWPuuPbuzV9542P5usS1qrabS","caType":"CPubKeyAddress","caTxNum":0,"caBalance":{"getCoin":"0"},"caTxList":[]}},
    "DdzFFzCqrht4im71gK9VsrbpqQ3hXmUktPekHGHYzZroSqLk2gBzPeEgVQ6vtumqSmcyNmdeMA7MTNeWhxavDVo7cepwPEqXxyFyyXu4" : {"Right":{"caAddress":"DdzFFzCqrht4im71gK9VsrbpqQ3hXmUktPekHGHYzZroSqLk2gBzPeEgVQ6vtumqSmcyNmdeMA7MTNeWhxavDVo7cepwPEqXxyFyyXu4","caType":"CPubKeyAddress","caTxNum":0,"caBalance":{"getCoin":"0"},"caTxList":[]}},
    "DdzFFzCqrhsi3CPXnAidDcHmgEmVyeGmgKV8qoSsnwzjAMjQQj2Rr6i5x2yv2qtqVeJiyvEoUpEMGNtD8xR1VJkX26j4yVoqo3WggEki" : {"Right":{"caAddress":"DdzFFzCqrhsi3CPXnAidDcHmgEmVyeGmgKV8qoSsnwzjAMjQQj2Rr6i5x2yv2qtqVeJiyvEoUpEMGNtD8xR1VJkX26j4yVoqo3WggEki","caType":"CPubKeyAddress","caTxNum":0,"caBalance":{"getCoin":"0"},"caTxList":[]}},
    "DdzFFzCqrht7nLWxuwUaJcAoBAb1M93sEgp1AAgm8VCqgGkAbVucpLGJEq1bxkeRtX7Jddd4wueJ73KHos7316dVjUScXf3uhpXgTjQd" : {"Right":{"caAddress":"DdzFFzCqrht7nLWxuwUaJcAoBAb1M93sEgp1AAgm8VCqgGkAbVucpLGJEq1bxkeRtX7Jddd4wueJ73KHos7316dVjUScXf3uhpXgTjQd","caType":"CPubKeyAddress","caTxNum":0,"caBalance":{"getCoin":"0"},"caTxList":[]}},
    "DdzFFzCqrht8KhWRRunt1iHt9oQhCpZFQgt6J4fGfCxvVu5as2NhanRusBYyKgrW8eXtfUCFXmeTGJRQkk9hyXLW4HcUE9KqMBFFxUBo" : {"Right":{"caAddress":"DdzFFzCqrht8KhWRRunt1iHt9oQhCpZFQgt6J4fGfCxvVu5as2NhanRusBYyKgrW8eXtfUCFXmeTGJRQkk9hyXLW4HcUE9KqMBFFxUBo","caType":"CPubKeyAddress","caTxNum":0,"caBalance":{"getCoin":"0"},"caTxList":[]}},
    "DdzFFzCqrhswQUeSvvYbArL3XHAnnk6VpgEgY6KMEi9fE8sSDPPK51FqLkNzGYf6Z9H7CfLrLhwqoGu4HTVvpWV5WwyvQyd3rrkuePSV" : {"Right":{"caAddress":"DdzFFzCqrhswQUeSvvYbArL3XHAnnk6VpgEgY6KMEi9fE8sSDPPK51FqLkNzGYf6Z9H7CfLrLhwqoGu4HTVvpWV5WwyvQyd3rrkuePSV","caType":"CPubKeyAddress","caTxNum":1,"caBalance":{"getCoin":"750000"},"caTxList":[{"ctbId":"3b8573d901522d73114b1c9671698d36b42931c863540fc699a636d3d93a1d68","ctbTimeIssued":1519820491,"ctbInputs":[["DdzFFzCqrhswXkREAGRUQRGm3fYnhiujfFsXELpP3FDfSA7atExtvqBuWSk8C5PwD9PnDF7qXJjs9yX48QpkqRVgV4YCfuiVAZN2rEVF",{"getCoin":"115078"}],["DdzFFzCqrhtAThjMBZNSbed3Dw7GmsEprFphaiasLVvCubwJ5oyfzntR9XDAAT8hCDmuAs2wCxXntcrQvxqsqBboiuCrHSApJnN8XebJ",{"getCoin":"821151"}]],"ctbOutputs":[["DdzFFzCqrhsoggT7JpYS5HeB4BXW5RP2gq8U4pSMmNkREGrby187nbeVDiXTHBAssvHHmVdf7xSRMnAxtR3yHLWqP4GVQqWcsMtVLM4R",{"getCoin":"7468"}],["DdzFFzCqrhswQUeSvvYbArL3XHAnnk6VpgEgY6KMEi9fE8sSDPPK51FqLkNzGYf6Z9H7CfLrLhwqoGu4HTVvpWV5WwyvQyd3rrkuePSV",{"getCoin":"750000"}]],"ctbInputSum":{"getCoin":"936229"},"ctbOutputSum":{"getCoin":"757468"}}]}},
    "DdzFFzCqrhsk4Eyx4CJyr1ymTEDef2A74gMykjTzcBYSV8iXBwYyMC89MJHMdV3itzsCPmc7Cr6yE2H6CRHioWjUs9XkA3UiQpSWzRgP" : {"Right":{"caAddress":"DdzFFzCqrhsk4Eyx4CJyr1ymTEDef2A74gMykjTzcBYSV8iXBwYyMC89MJHMdV3itzsCPmc7Cr6yE2H6CRHioWjUs9XkA3UiQpSWzRgP","caType":"CPubKeyAddress","caTxNum":0,"caBalance":{"getCoin":"0"},"caTxList":[]}},
    "DdzFFzCqrhsvoV83E3MKsrvSLXYMZcTUbTQnTi8gsWsLWPsowVeKADN8phbQ5kkzqGWveFCW4r7SUotDYiGgwdRu67QRRbqTets5jA7g" : {"Right":{"caAddress":"DdzFFzCqrhsvoV83E3MKsrvSLXYMZcTUbTQnTi8gsWsLWPsowVeKADN8phbQ5kkzqGWveFCW4r7SUotDYiGgwdRu67QRRbqTets5jA7g","caType":"CPubKeyAddress","caTxNum":0,"caBalance":{"getCoin":"0"},"caTxList":[]}},
    "DdzFFzCqrht4Nb7C6niLFvwV3Jwdn2iRZoiBaDqCUdcVChYPZSMh4D8nNpHJtSY9KRF3go2CzVrESmCTjrAQmxYY3S2MDdp2k22sQV8r" : {"Right":{"caAddress":"DdzFFzCqrht4Nb7C6niLFvwV3Jwdn2iRZoiBaDqCUdcVChYPZSMh4D8nNpHJtSY9KRF3go2CzVrESmCTjrAQmxYY3S2MDdp2k22sQV8r","caType":"CPubKeyAddress","caTxNum":0,"caBalance":{"getCoin":"0"},"caTxList":[]}},
    "DdzFFzCqrhseq4DEn7FgcjTQoXXTy9A6wNasdNJT2aapydxAgHLhxMNn9ByQtXhNUKLwku3AQp3usHtvcbNncqyUTuf34ZLQVnA7Bq5J" : {"Right":{"caAddress":"DdzFFzCqrhseq4DEn7FgcjTQoXXTy9A6wNasdNJT2aapydxAgHLhxMNn9ByQtXhNUKLwku3AQp3usHtvcbNncqyUTuf34ZLQVnA7Bq5J","caType":"CPubKeyAddress","caTxNum":0,"caBalance":{"getCoin":"0"},"caTxList":[]}},
    "DdzFFzCqrhspG8UcV5EWC8ZZ51PhiYdrjBF5K8VwugoW75hNWcsgiiGwt19XK6Wjwrj9Dgo8MFLr3p5NqCpmGpwr1feSbknQQWWZnAqu" : {"Right":{"caAddress":"DdzFFzCqrhspG8UcV5EWC8ZZ51PhiYdrjBF5K8VwugoW75hNWcsgiiGwt19XK6Wjwrj9Dgo8MFLr3p5NqCpmGpwr1feSbknQQWWZnAqu","caType":"CPubKeyAddress","caTxNum":0,"caBalance":{"getCoin":"0"},"caTxList":[]}},
github tektoncd / dashboard / config_frontend / setupTests.js View on Github external
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import 'react-testing-library/cleanup-after-each';
import fetchMock from 'fetch-mock';

fetchMock.catch();
fetchMock.config.overwriteRoutes = true;
github google / skia-buildbot / ct / modules / patch-sk / patch-sk-demo.ts View on Github external
import './index';
import '../../../infra-sk/modules/theme-chooser-sk';
import { $$ } from 'common-sk/modules/dom';
import fetchMock from 'fetch-mock';
import {
  chromiumPatchResult,
} from './test_data';
import { PatchSk } from './patch-sk';

fetchMock.config.overwriteRoutes = false;
fetchMock.postOnce('begin:/_/cl_data', chromiumPatchResult, { delay: 1000 });
fetchMock.post('*', 503);
const tq = document.createElement('patch-sk') as PatchSk;
tq.patchType = 'chromium';
($$('#container') as HTMLElement).appendChild(tq);
github manifoldco / ui / docs / src / pages / index.tsx View on Github external
import React from 'react';
import { ThemeProvider } from 'styled-components';
import { graphql } from 'gatsby';
import { defineCustomElements } from '@manifoldco/ui/dist/loader';
import fetchMock from 'fetch-mock';

import Page from '../components/Page';
import theme from '../lib/theme';
import { mockPlans, mockProducts, mockProviders, mockRegions } from '../utils/mockCatalog';
import { mockResources } from '../utils/mockMarketplace';
import { mockGraphQl } from '../utils/mockGraphql';

fetchMock.config.fallbackToNetwork = true;
fetchMock.config.overwriteRoutes = true;

if (typeof window !== 'undefined') {
  defineCustomElements(window);
}

interface HomePageProps {
  data?: {
    home: MarkdownRemark.Data;
    page: MarkdownRemark.Data;
    toc: { edges: { node: MarkdownRemark.Data }[] };
    providers: { edges: { node: { data: Manifold.ManifoldNode; requestDuration: number } }[] };
    products: { edges: { node: { data: Manifold.ManifoldNode; requestDuration: number } }[] };
    plans: { edges: { node: { data: Manifold.ManifoldNode; requestDuration: number } }[] };
    regions: { edges: { node: { data: Manifold.ManifoldNode; requestDuration: number } }[] };
  };
}
github google / skia-buildbot / ct / modules / task-queue-sk / task-queue-sk-demo.ts View on Github external
function newTaskQueue(parentSelector: string) {
  fetchMock.config.overwriteRoutes = false;
  fetchMock.postOnce('begin:/_/get_', resultSetTwoItems);
  fetchMock.postOnce('begin:/_/get_', singleResultCanDelete);
  fetchMock.postOnce('begin:/_/get_', singleResultNoDelete);
  fetchMock.post('begin:/_/get_', 200, { repeat: 13 });
  const tq = document.createElement('task-queue-sk');
  ($$(parentSelector) as HTMLElement).appendChild(tq);
}