How to use the jest-fetch-mock.mockResponses 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 / delete-old-branches.spec.js View on Github external
test('', async () => {
    mockedChildProcess.__setResponse('git rev-parse --abbrev-ref HEAD', 'feature/my-feature-branch');

    const deleteOldBranches = require('../../lib/commands/delete-old-branches');

    mockedChildProcess.__setResponse('git fetch', ' ');
    mockedChildProcess.__setResponse('git log -1 --format=%cd origin/master', 'Fri May 4 10:40:15 2018 +0300');
    mockedChildProcess.__setResponse('git ls-remote --heads', 'refs/heads/master');

    mockedFetch.mockResponses(
      [
        // https://api.crowdin.com/api/project/info
        JSON.stringify({
          files: [
            {
              node_type: 'branch',
              name: 'sample-old-branch',
              files: [{
                node_type: 'file',
                name: 'sample-file-name.json',
                last_updated: 'Fri May 4 10:40:15 2018 +0300'
              }]
            }
          ]
        }),
        { status: 200 }
github yuriykuzin / crowdin-helper / test / commands / upload-sources.spec.js View on Github external
test('should perform upload source and then download and unzip translation', async () => {
    mockedChildProcess.__setResponse('git rev-parse --abbrev-ref HEAD', 'feature/my-feature-branch');

    const uploadSources = require('../../lib/commands/upload-sources');
    expect(consoleData.indexOf('Working on git branch: feature/my-feature-branch') !== -1).toBeTruthy();
    consoleData = '';

    mockedFetch.mockResponses(
      [
        // https://api.crowdin.com/api/project/my-project-name/add-directory
        JSON.stringify({ success: true }),
        { status: 200 }
      ],
      [
        // https://api.crowdin.com/api/project/my-project-name/add-directory
        JSON.stringify({ success: true }),
        { status: 200 }
      ],
      [
        // https://api.crowdin.com/api/project/my-project-name/add-file
        JSON.stringify({ success: true }),
        { status: 200 }
      ],
      [
github yuriykuzin / crowdin-helper / test / commands / download-translations.spec.js View on Github external
test('should perform upload source and then download and unzip translation', async () => {
    mockedChildProcess.__setResponse('git rev-parse --abbrev-ref HEAD', 'feature/my-feature-branch');

    const downloadTranslations = require('../../lib/commands/download-translations');
    expect(consoleData.indexOf('Working on git branch: feature/my-feature-branch') !== -1).toBeTruthy();
    consoleData = '';

    mockedFetch.mockResponses(
      [
        // https://api.crowdin.com/api/project/my-project-name/add-directory
        JSON.stringify({ success: true }),
        { status: 200 }
      ],
      [
        // https://api.crowdin.com/api/project/my-project-name/add-directory
        JSON.stringify({ success: true }),
        { status: 200 }
      ],
      [
        // https://api.crowdin.com/api/project/my-project-name/add-file
        JSON.stringify({ success: true }),
        { status: 200 }
      ],
      [
github yuriykuzin / crowdin-helper / test / commands / trigger-auto-translation.spec.js View on Github external
test('should say "no new phrases" if phrases === 0', async () => {
    mockedChildProcess.__setResponse('git rev-parse --abbrev-ref HEAD', 'feature/my-feature-branch');

    const triggerAutoTranslation = require('../../lib/commands/trigger-auto-translation');
    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 / check-progress-on-branch.spec.js View on Github external
test('should trigger auto translate and then exit on master branch', async () => {
    mockedChildProcess.__setResponse('git rev-parse --abbrev-ref HEAD', 'master');

    const checkProgressOnBranch = require('../../lib/commands/check-progress-on-branch');
    expect(consoleData.indexOf('Working on git branch: master') !== -1).toBeTruthy();
    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 geostyler / geostyler-wfs-parser / src / WfsDataParser.spec.ts View on Github external
}, {
          'type': 'Feature',
          'id': 'osm-busstops.fid-4dec2e09_163976bf70d_-73ab',
          'geometry': {
            'type': 'Point',
            'coordinates': [981048.0170072, 7001258.45667367]
          },
          'geometry_name': 'geometry',
          'properties': {
            'osm_id': 29077474
          }
        }]
      };

      // mock responses of WFS DescribeFeatureType and WFS GetFeature
      fetch.mockResponses([describeFeatureTypeResponse], [JSON.stringify(getFeatureResponse)]);

      const wfsParser = new WfsDataParser();
      const resultPromise = wfsParser.readData({
        url: '//ows.terrestris.de/geoserver/osm/wfs',
        version: '2.0.0',
        typeName: 'osm:osm-country-borders',
        maxFeatures: 1
      });

      const onFullFilled = (result: any) => {
        expect(result).toBeDefined();
        expect(result.schema.type).toEqual('object');
        expect(typeof result.schema.properties).toBe('object');
        expect(result.schema.properties.osm_id).toEqual({
          type: 'number'
        });