How to use the superagent.__setMockResponse function in superagent

To help you get started, we’ve selected a few superagent 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 OpenNeuroOrg / openneuro / packages / openneuro-server / datalad / __tests__ / snapshots.spec.js View on Github external
it('posts to the DataLad /datasets/{dsId}/snapshots/{snapshot} endpoint', async done => {
      const tag = 'snapshot'
      const dsId = await createDataset()
      // Reset call count for request.post
      request.post.mockClear()
      request.__setMockResponse({ body: {} })
      await createSnapshot(dsId, tag, false)
      expect(request.post).toHaveBeenCalledTimes(1)
      expect(request.post).toHaveBeenCalledWith(
        expect.stringContaining(
          `${config.datalad.uri}/datasets/${dsId}/snapshots/${tag}`,
        ),
      )
      done()
    })
  })
github thelinmichael / spotify-web-api-node / __tests__ / http-manager.js View on Github external
test('Should make a successful POST request', done => {
    superagent.__setMockResponse({
      status: 200,
      data: 'some data'
    });
    var HttpManager = require('../src/http-manager');
    var request = Request.builder()
      .withHost('such.api.wow')
      .withPort(1337)
      .withScheme('http')
      .build();

    HttpManager.post(request, function(errorObject) {
      done(errorObject);
    });
  });
github OpenNeuroOrg / openneuro / packages / openneuro-server / datalad / __tests__ / description.spec.js View on Github external
it('handles a corrupted response', end => {
    request.post.mockClear()
    request.__setMockResponse({
      body: Buffer.from('0x5f3759df', 'hex'),
    })
    getDescriptionObject('ds000001')([
      { filename: 'dataset_description.json', id: '12345' },
    ]).then(description => {
      expect(description).toEqual(defaultDescription)
      end()
    })
  })
  it('works without a dataset_description.json being present', end => {
github Sage / carbon / src / components / table-ajax / __spec__.js View on Github external
it('on success sets the totalRecords on the pager and sets data-state to loaded', () => {
      Request.__setMockResponse({
        status() {
          return 200;
        },
        ok() {
          return true;
        },
        body: {
          records: 1
        }
      });
      instance.emitOnChangeCallback('data', options);
      jest.runTimersToTime(251);
      wrapper.update();
      const pager = wrapper.find(Pager);

      expect(pager.props().totalRecords).toEqual('1');
github Sage / carbon / src / components / table-ajax / __spec__.js View on Github external
beforeEach(() => {
      Request.__setMockResponse(response);
      Request.__setMockError(error);
      jest.useFakeTimers();
    });
github Sage / carbon / src / components / dropdown-filter-ajax / __spec__.js View on Github external
beforeEach(() => {
      Request.__setMockResponse({
        status() {
          return 200;
        },
        ok() {
          return true;
        },
        body: {
          data: [{
            records: 1,
            items: [ 1 ],
            page: 1
          }]
        }
      });
      Request.abort = jest.fn().mockReturnThis();
      wrapper = mount();
github Sage / carbon / src / utils / helpers / poller / __spec__.js View on Github external
beforeEach(() => {
        Request.__setMockResponse({
          status() {
            return 500;
          },
          ok() {
            return false;
          },
          body: {
            message_type: 'error'
          }
        });

        Request.__setMockError({
          message: 'Unsuccessful HTTP response'
        });
      });