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

To help you get started, we’ve selected a few 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 Workfront / workfront-api / test / integration / create.spec.ts View on Github external
return this.api.create(objCode, params, fields).then(function() {
            const [url, opts] = fetchMock.lastCall('create')
            should(url).endWith(objCode + '?fields=' + encodeURIComponent('*,zzz:*'))
            should(opts.method).equal('POST')
            should(opts.body).equal('{"foo":"bar"}')
        })
    })
github auth0 / react-native-auth0 / src / auth / __tests__ / index.spec.js View on Github external
it('should send correct payload with username', async () => {
      fetchMock.postOnce(
        'https://samples.auth0.com/dbconnections/signup',
        success
      );
      expect.assertions(1);
      await auth.createUser({ ...parameters, usename: 'info' });
      expect(fetchMock.lastCall()).toMatchSnapshot();
    });
github Workfront / workfront-api / test / integration / copy.spec.ts View on Github external
return this.api.copy('foo', 'bar', {name: 'Copy of bar'}).then(function() {
                const [url, opts] = fetchMock.lastCall('copy')
                should(url).endWith('foo')
                should(opts.method).equal('POST')
                should(opts.body).containEql('updates=' + encodeURIComponent('{"name":"Copy of bar"}'))
                should(opts.body).containEql('copySourceID=bar')
                should(opts.body).not.containEql('options')
            })
        })
github vmurin / react-native-azure-auth / src / auth / __tests__ / auth.spec.js View on Github external
it('should send correct payload', async () => {
            fetchMock.postOnce('https://login.microsoftonline.com/common/oauth2/v2.0/token', tokens)
            expect.assertions(1)
            await auth.refreshTokens(parameters)
            expect(fetchMock.lastCall()).toMatchSnapshot()
        })
github apollographql / apollo-client / src / link / http / __tests__ / HttpLink.ts View on Github external
complete: () => {
          try {
            let body = convertBatchedBody(fetchMock.lastCall()[1].body);
            expect(body.query).toBe(print(sampleMutation));
            expect(body.variables).toEqual(variables);
            expect(body.context).not.toBeDefined();
            if (includeExtensions) {
              expect(body.extensions).toBeDefined();
            } else {
              expect(body.extensions).not.toBeDefined();
            }
            expect(next).toHaveBeenCalledTimes(1);

            after();
          } catch (e) {
            done.fail(e);
          }
        },
      });
github apollographql / apollo-link / packages / apollo-link-http / src / __tests__ / sharedHttpTests.ts View on Github external
complete: () => {
          try {
            let body = convertBatchedBody(fetchMock.lastCall()[1].body);
            expect(body.query).toBe(print(sampleMutation));
            expect(body.variables).toEqual(variables);
            expect(body.context).not.toBeDefined();
            if (includeExtensions) {
              expect(body.extensions).toBeDefined();
            } else {
              expect(body.extensions).not.toBeDefined();
            }
            expect(next).toHaveBeenCalledTimes(1);

            after();
          } catch (e) {
            done.fail(e);
          }
        },
      });
github openfun / marsha / src / frontend / data / sideEffects / createThumbnail / index.spec.ts View on Github external
it('creates a new thumbnail and return it', async () => {
    fetchMock.mock('/api/thumbnails/', {
      id: '42',
      ready_to_display: false,
      urls: null,
    });

    const thumbnail = await createThumbnail();

    const fetchArgs = fetchMock.lastCall()![1]!;

    expect(thumbnail).toEqual({
      id: '42',
      ready_to_display: false,
      urls: null,
    });
    expect(fetchArgs.headers).toEqual({
      Authorization: 'Bearer token',
      'Content-Type': 'application/json',
    });
    expect(fetchArgs.method).toEqual('POST');
  });
github jamaljsr / polar / src / lib / lightning / clightning / clightningApi.spec.ts View on Github external
it('should perform a successful httpPost', async () => {
    fetchMock.once('end:/post-ok', { success: true });
    const res = await httpPost(node, 'post-ok', { data: 'asdf' });
    expect(res).toEqual({ success: true });
    const lastCall = fetchMock.lastCall() as any;
    expect(lastCall).toBeInstanceOf(Array);
    expect(lastCall[1].body).toEqual('{"data":"asdf"}');
  });
github openfun / marsha / src / frontend / components / DashboardVideoPaneDownloadOption / index.spec.tsx View on Github external
'checked',
      false,
    );

    await act(async () => {
      fireEvent.click(getByLabelText('Allow video download'));
      return deferred.resolve({ ...video, show_download: true });
    });

    expect(getByLabelText('Allow video download')).toHaveProperty(
      'checked',
      true,
    );
    expect(fetchMock.calls()).toHaveLength(1);
    expect(fetchMock.lastCall()![0]).toEqual('/api/videos/442/');
    expect(fetchMock.lastCall()![1]!.body).toEqual(
      JSON.stringify({
        ...video,
        show_download: true,
      }),
    );
  });
});
github manifoldco / ui / src / utils / restFetch.spec.ts View on Github external
nonCatalogServices.forEach(async service => {
      const fetcher = createRestFetch({
        wait: () => 1,
        getAuthToken: () => '1234',
      });
      fetchMock.mock('path:/v1/test', 200);
      await fetcher({ endpoint: '/test', service });
      const [, req] = fetchMock.lastCall() as any;
      return expect(req.headers).toEqual({ authorization: 'Bearer 1234' });
    }));