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

To help you get started, we’ve selected a few node-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 lewie9021 / appdriver / __tests__ / helpers / mockRequests.js View on Github external
const post = ({url, status, payload, response, name}) => {
  if (!requests.length) {
    fetch.mockImplementation(fetchMock);
  }

  const requestId = requests.length;

  requests.push({
    method: "POST",
    url,
    payload,
    status,
    response,
    requestId,
    calls: []
  });

  return requestId;
};
github TheBrainFamily / TheBrain2.0 / server / src / api / resolvers-graphql.spec.js View on Github external
beforeEach(async () => {
    fetch.mockClear()
    fetch.mockImplementation(async (query) => {
      if (query.includes(`https://graph.facebook.com/me?access_token=correctAccessToken`)) {
        return {
          json: () => ({id: 'testFbUserId'})
        }
      }
      if (query.includes(`https://graph.facebook.com/app/?access_token=correctAccessToken`)) {
        return {
          json: () => ({id: 'MOCKED_FB_APP_ID'})
        }
      }
      if (query.includes(`https://graph.facebook.com/v2.10/`)) {
        return {
          json: () => ({id: 'testFbUserId', name: 'testUserName', email: 'test@thebrain.pro'})
        }
      }
      return {