How to use the jest-fetch-mock.mockResponse 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 wq / wq.app / packages / chart / src / __tests__ / pandas.js View on Github external
test('pandas.get()', async () => {
    mockFetch.mockResponse(fs.readFileSync(__dirname + '/data.csv'));
    var data = await pandas.get('data.csv');
    expect(data).toEqual([
        {
            site: 'SITE1',
            parameter: 'PARAM1',
            data: [
                { date: '2014-01-01', value: 0.5 },
                { date: '2014-01-02', value: 0.1 }
            ]
        },
        {
            site: 'SITE2',
            parameter: 'PARAM1',
            data: [
                { date: '2014-01-01', value: 0.5 },
                { date: '2014-01-02', value: 0.5 }
github BlueBrain / nexus-js / src / Resource / __tests__ / Resource.spec.ts View on Github external
it('should call httpGet method with the proper accept header', async () => {
        mockResponse(mockDotResponse, { status: 200 });
        const resource = new Resource(
          'testOrg',
          'testProject',
          mockResourceResponse,
        );
        await resource.getAs(ResourceGetFormat.DOT);
        expect(mock.calls[0][0]).toEqual(mockResourceResponse['_self']);
        expect(mock.calls[0][1].headers.get('Accept')).toBe(
          'text/vnd.graphviz',
        );
      });
    });
github BlueBrain / nexus-js / src / File / __tests__ / file.spec.ts View on Github external
it('should request the raw file', async () => {
      mockResponse(fakeFile, { status: 200 });
      const file = new NexusFile('testOrg', 'testProject', mockFileResponse);
      await file.getFile();
      const headers = mock.calls[0][1].headers;
      expect(headers.get('Accept')).toBe('*/*');
      expect(file.rawFile).toEqual(btoa(fakeFile));
    });
  });
github unosquare / tubular-react / test / RemoteDataSource.spec.tsx View on Github external
test('Should contain data with valid url', async (done) => {
    fetch.mockResponse(JSON.stringify(simpleRecordsExpected));

    const component = shallow();
    await (component.instance() as any).processRequest({});
    expect(component.state('data')).toEqual(simpleRecordsExpected.Payload);
    done();
  });
github BlueBrain / nexus-js / src / View / SparqlView / __tests__ / SparqlView.spec.ts View on Github external
it('should get the Sparql view', async () => {
    mockResponse(JSON.stringify(mockSparqlViewResponse));
    const view: SparqlView = await SparqlView.get(orgLabel, projectLabel);
    expect(mock.calls.length).toBe(1);
    expect(view.id).toBe(mockSparqlViewResponse['@id']);
    expect(view.deprecated).toBe(mockSparqlViewResponse._deprecated);
    expect(view.orgLabel).toBe('my-org');
    expect(view.projectLabel).toBe('example');
    expect(view.rev).toBe(mockSparqlViewResponse._rev);
    expect(view.type).toEqual(mockSparqlViewResponse['@type']);
    expect(view.uuid).toBe(mockSparqlViewResponse._uuid);
  });
github BlueBrain / nexus-js / src / utils / __tests__ / http.spec.ts View on Github external
it('should successfully parse prepare File', async () => {
      const payload = { message: 'success' };
      mockResponse(JSON.stringify(payload), { status: 200 });
      const blob = new Blob(['abc'], { type: 'tet/plain ' });
      httpPost('/endpoint', blob, {
        sendAs: HttpConfigTypes.FILE,
      });
      expect(mock.calls[0][1].body).toEqual(blob);
    });
    it('should throw an error', async () => {
github BlueBrain / nexus-js / src / Resource / __tests__ / Resource.spec.ts View on Github external
beforeEach(() => {
      mockResponse(JSON.stringify(mockResourceResponse), { status: 200 });
    });
github BlueBrain / nexus-js / src / Project / __tests__ / Project.spec.ts View on Github external
beforeEach(() => {
      mockResponse('{}');
    });
    afterEach(() => {
github TinkoffCreditSystems / tinkoff-request / packages / plugin-protocol-http / src / http.spec.ts View on Github external
it('request with custom agent', async () => {
        const response = { a: 3 };
        const mockResponse = jest.fn(() =>
            Promise.resolve({
                body: JSON.stringify(response),
                init: {
                    headers: {
                        'Content-type': 'application/json;',
                    },
                },
            })
        );

        fetch.mockResponse(mockResponse);

        class MockedAgent {
            requests() {}
            destroy() {}
        }

        http({ agent: { http: new MockedAgent() as any, https: new MockedAgent() as any } }).init(
            new Context({ request: { url: 'http://test.com/api' } }),
            next,
            null
        );

        await new Promise((res) => {
            next.mockImplementation(res);
        });