How to use the cross-fetch.mockImplementation function in cross-fetch

To help you get started, we’ve selected a few cross-fetch 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 okta / okta-auth-js / test / util / util.js View on Github external
} else {
      allPairs.unshift(pair);
    }
  }

  function done() {
    if (allPairs.length !== 0) {
      throw new Error('Not all staged XHRs were executed');
    }
  }

  if (pairs) {
    setNextPair(pairs);
  }

  fetch.mockImplementation(function (url, args) {
    var pair = allPairs.shift();
    if (!pair) {
      throw new Error('We are making a request that we have not anticipated.');
    }

    if (pair.request.withCredentials !== false) {
      // Make sure every request is attaching cookies
      expect(args.credentials).toEqual('include');
    }

    if (pair.request) {
      expect(pair.request.uri).toEqual(url);

      if (pair.request.headers) {
        expect(pair.request.headers).toEqual(args.headers);
      }
github okta / okta-auth-js / test / support / util.js View on Github external
} else {
      allPairs.unshift(pair);
    }
  }

  function done() {
    if (allPairs.length !== 0) {
      throw new Error('Not all staged XHRs were executed');
    }
  }

  if (pairs) {
    setNextPair(pairs);
  }

  fetch.mockImplementation(function (url, args) {
    var pair = allPairs.shift();
    if (!pair) {
      throw new Error('We are making a request that we have not anticipated.');
    }

    if (pair.request.withCredentials !== false) {
      // Make sure every request is attaching cookies
      expect(args.credentials).toEqual('include');
    }

    if (pair.request) {
      expect(pair.request.uri).toEqual(url);

      if (pair.request.headers) {
        expect(pair.request.headers).toEqual(args.headers);
      }