How to use the fetch-mock.sandbox 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 decentralized-identity / sidetree / tests / core / Observer.spec.ts View on Github external
beforeAll(async () => {
    jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000; // These asynchronous tests can take a bit longer than normal.

    mockCasFetch = fetchMock.sandbox().get('*', 404); // Setting the CAS to always return 404.
    cas = new CasClient(config.contentAddressableStoreServiceUri, mockCasFetch);
    downloadManager = new DownloadManager(config.maxConcurrentDownloads, cas);
    operationStore = new MockOperationStore();
    operationProcessor = new OperationProcessor(config.didMethodName, operationStore);

    downloadManager.start();
  });
github voluntarily / vly2 / components / Person / __tests__ / PersonBadge.spec.js View on Github external
test('PersonBadge renders properly', async t => {
  const mockServer = mockFetch.sandbox()
  mockServer.get(`begin:${APP_URL}/api/badge`, { body: [...badgeData] })
  const person = {
    _id: 'taskldjfh0'
  }
  global.fetch = mockServer
  const PersonBadgeRendered = mount()
  t.true(PersonBadgeRendered.exists())
})
github dropbox / dropbox-sdk-js / test / rpc-request-error.js View on Github external
it('handles errors in expected format', function (done) {

    const fetchMock = FetchMock.sandbox().mock('*', function () {
      return {
        status: 500,
        body: JSON.stringify(exampleErr),
        headers: {
          'Content-Type': 'application/json',
        },
      };
    }).catch(500);

    rpcRequest(fetchMock)('files/list', { foo: 'bar' }, 'user', 'api', 'atoken')
      .then(function (data) {
        done(new Error('shouldn’t reach this callback'));
      })
      .catch(function (err) {
        assert(err);
        assert.equal(err.status, 500);
github voluntarily / vly2 / __tests__ / op / opdetailpage.spec.js View on Github external
function makeFetchMock (opportunityId) {
  const myMock = fetchMock.sandbox()
  myMock.get(API_URL + '/interests/?op=' + opportunityId, { body: { status: 200 } })
  return myMock
}
github dropbox / dropbox-sdk-js / test / upload-request.js View on Github external
beforeEach(function () {
    fetchMock = FetchMock.sandbox().post('*', new Response(
      '{"foo": "bar"}',
      {
        status: 200,
        statusText: "OK",
        headers: {
          'Content-Type': 'application/json',
          'dropbox-api-result': '{"test":"json"}'
        }
      }
    ));
  });
github dropbox / dropbox-sdk-js / test / rpc-request.js View on Github external
beforeEach(function () {
    fetchMock = FetchMock.sandbox().mock('*', new Response(
      '{"test": "test"}',
      {
        status: 200,
        statusText: "OK",
        headers: {
          'Content-Type': 'application/json',
          'dropbox-api-result': '{"test":"json"}'
        }
      }
    ));
  });
github decentralized-identity / sidetree / tests / core / Observer.spec.ts View on Github external
afterEach(() => {
    fetchMock.sandbox().reset();
    fetchMock.reset();
  });
github stoplightio / spectral / setupKarma.ts View on Github external
beforeEach(() => {
  fetchMock = require('fetch-mock').sandbox();
  window.fetch = fetchMock;

  fetchMock.get('https://unpkg.com/@stoplight/spectral/rulesets/oas/index.json', {
    status: 200,
    body: JSON.parse(JSON.stringify(oasRuleset)),
  });

  fetchMock.get('https://unpkg.com/@stoplight/spectral/rulesets/oas/schemas/schema.oas2.json.json', {
    status: 200,
    body: JSON.parse(JSON.stringify(oas2Schema)),
  });

  fetchMock.get('https://unpkg.com/@stoplight/spectral/rulesets/oas/schemas/schema.oas3.json.json', {
    status: 200,
    body: JSON.parse(JSON.stringify(oas3Schema)),
  });
github quiltdata / quilt / catalog / app / utils / APIConnector.spec.js View on Github external
const setup = () => {
      const history = createHistory({ initialEntries: ['/'] });
      const store = configureStore(fromJS({}), history);
      const request = (opts) => store.runSaga(apiRequest, opts).done;
      const fetch = fetchMock.sandbox();
      const tree = nest(
        [StoreProvider, { store }],
        [APIProvider, { fetch, base }],
        () =&gt; <h1>sup</h1>,
      );

      return { request, fetch, tree };
    };