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

To help you get started, we’ve selected a few jest-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 yuriykuzin / crowdin-helper / test / commands / check-progress-on-branch.spec.js View on Github external
consoleData = '';

    mockedFetch.mockResponses(
      [
        // https://api.crowdin.com/api/project/pre-translate
        JSON.stringify({
          success: true
        }),
        { status: 200 }
      ]
    );

    await checkProgressOnBranch();

    expect(consoleData.indexOf('No validation performed since it is a master branch') !== -1).toBeTruthy();
    expect(mockedFetch.mock.calls[0][0]).toEqual('https://api.crowdin.com/api/project/my-project-name/pre-translate');
  });
github yuriykuzin / crowdin-helper / test / commands / trigger-auto-translation.spec.js View on Github external
expect(consoleData.indexOf('Working on git branch: feature/my-feature-branch') !== -1).toBeTruthy();
    consoleData = '';

    mockedFetch.mockResponses(
      [
        // https://api.crowdin.com/api/project/pre-translate
        JSON.stringify({
          success: true
        }),
        { status: 200 }
      ]
    );

    await triggerAutoTranslation();

    expect(mockedFetch.mock.calls[0][0]).toEqual('https://api.crowdin.com/api/project/my-project-name/pre-translate');
  });
});
github yuriykuzin / crowdin-helper / test / commands / delete-old-branches.spec.js View on Github external
}),
        { status: 200 }
      ],
      [
        // https://api.crowdin.com/api/project/delete-directory
        JSON.stringify({
          success: true
        }),
        { status: 200 }
      ]
    );

    await deleteOldBranches();

    expect(consoleData.indexOf('Branch "sample-old-branch" is removed from crowdin') !== -1).toBeTruthy();
    expect(mockedFetch.mock.calls[1][0])
      .toEqual('https://api.crowdin.com/api/project/my-project-name/delete-directory');
  });
});
github yuriykuzin / crowdin-helper / test / commands / upload-sources.spec.js View on Github external
],
      [
        // https://api.crowdin.com/api/project/my-project-name/add-file
        JSON.stringify({ success: true }),
        { status: 200 }
      ],
      [
        // https://api.crowdin.com/api/project/my-project-name/pre-translate
        JSON.stringify({ success: true }),
        { status: 200 }
      ]
    );

    await uploadSources();

    expect(mockedFetch.mock.calls[2][1].body._streams[7].source._readableState.buffer)
      .toEqual(fs.createReadStream('test/sample-source-file/en.json')._readableState.buffer);

    expect(consoleData.indexOf('Uploading to branch: feature--my-feature-branch') !== -1).toBeTruthy();
    expect(consoleData.indexOf('test/sample-source-file/en.json is uploaded') !== -1).toBeTruthy();
    expect(consoleData.indexOf('Triggering auto-translation of a branch: feature--my-feature-branch') !== -1).toBeTruthy();

    const properApiCallsOrder = [
      'https://api.crowdin.com/api/project/my-project-name/add-directory',
      'https://api.crowdin.com/api/project/my-project-name/add-directory',
      'https://api.crowdin.com/api/project/my-project-name/add-file',
      'https://api.crowdin.com/api/project/my-project-name/pre-translate'
    ];

    properApiCallsOrder.forEach((apiCall, index) => {
      expect(mockedFetch.mock.calls[index][0]).toEqual(apiCall);
    })
github yuriykuzin / crowdin-helper / test / crowdin-fetch.spec.js View on Github external
test('crowdinFetch calls node-fetch, sends FormData and gets sample JSON response', async () => {
    const response = await crowdinFetch('export');
    const firstFetchArgument = fetch.mock.calls[0][0];
    const secondFetchArgument = fetch.mock.calls[0][1];

    expect(firstFetchArgument).toEqual('https://api.crowdin.com/api/project/my-project-name/export');
    expect(secondFetchArgument.method).toBe('POST');
    expect(secondFetchArgument.body._streams).toBeDefined();
    expect(secondFetchArgument.body._streams[1]).toBe('my-project-api-key');
    expect(response).toEqual(sampleResponse);
  });
github yuriykuzin / crowdin-helper / test / utilites / crowdin-api.spec.js View on Github external
test('CrowdinApi.buildBranch calls node-fetch, sends FormData and gets sample JSON response', async () => {
    const response = await CrowdinApi.buildBranch('sample-feature-branch-name');

    const firstFetchArgument = fetch.mock.calls[0][0];
    const secondFetchArgument = fetch.mock.calls[0][1];

    expect(firstFetchArgument).toEqual('https://api.crowdin.com/api/project/my-project-name/export');
    expect(secondFetchArgument.method).toBe('POST');
    expect(secondFetchArgument.body._streams).toBeDefined();
    expect(secondFetchArgument.body._streams[1]).toBe('my-project-api-key');
    expect(response).toEqual(sampleResponse);
  });
github yuriykuzin / crowdin-helper / test / commands / check-progress-on-branch.spec.js View on Github external
JSON.stringify({
          files: [{
            node_type: 'branch',
            name: 'feature--my-feature-branch',
            phrases: 0
          }]
        }),
        { status: 200 }
      ]
    );

    await checkProgressOnBranch();

    expect(consoleData.indexOf('Crowdin: Checking language: nl') !== -1).toBeTruthy();
    expect(consoleData.indexOf('Okay, no new phrases in this branch') !== -1).toBeTruthy();
    expect(mockedFetch.mock.calls[0][0]).toEqual('https://api.crowdin.com/api/project/my-project-name/language-status');
  });
github yuriykuzin / crowdin-helper / test / commands / download-translations.spec.js View on Github external
properApiCallsOrder.forEach((apiCall, index) => {
      expect(mockedFetch.mock.calls[index][0]).toEqual(apiCall);
    })
  });
github yuriykuzin / crowdin-helper / test / commands / download-translations.spec.js View on Github external
autodrain: () => null
              });

              return {
                promise: () => Promise.resolve()
              };
            }
          })
        },
        { status: 200 }
      ],
    );

    await downloadTranslations(true);

    expect(mockedFetch.mock.calls[2][1].body._streams[7].source._readableState.buffer)
      .toEqual(fs.createReadStream('test/sample-source-file/en.json')._readableState.buffer);

    expect(consoleData.indexOf('Uploading to branch: feature--my-feature-branch') !== -1).toBeTruthy();
    expect(consoleData.indexOf('Triggering auto-translation of a branch: feature--my-feature-branch') !== -1).toBeTruthy();
    expect(consoleData.indexOf('Triggering branch build before downloading') !== -1).toBeTruthy();
    expect(consoleData.indexOf('Unzipped sample-translation-folder/nl.json') !== -1).toBeTruthy();

    const properApiCallsOrder = [
      'https://api.crowdin.com/api/project/my-project-name/add-directory',
      'https://api.crowdin.com/api/project/my-project-name/add-directory',
      'https://api.crowdin.com/api/project/my-project-name/add-file',
      'https://api.crowdin.com/api/project/my-project-name/pre-translate',
      'https://api.crowdin.com/api/project/my-project-name/export',
      'https://api.crowdin.com/api/project/my-project-name/download/all.zip'
    ];
github yuriykuzin / crowdin-helper / test / commands / upload-sources.spec.js View on Github external
properApiCallsOrder.forEach((apiCall, index) => {
      expect(mockedFetch.mock.calls[index][0]).toEqual(apiCall);
    })
  });