How to use the fetch-mock.called 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 Rsullivan00 / apollo-link-json-api / src / __tests__ / jsonApiLink.ts View on Github external
query: encodedQuery,
        variables: { name: 'Love apollo' },
      }),
    );

    expect(fetchMock.called('/api/posts?name=Love%20apollo')).toBe(true);

    await makePromise(
      execute(link, {
        operationName: 'postQuery',
        query: mixedQuery,
        variables: { id: 1, query: { comments: 5 } },
      }),
    );

    expect(fetchMock.called('/api/posts/1?comments=5')).toBe(true);
  });
  // TODO: Test for Path using context
github openfun / marsha / src / frontend / components / DashboardVideoPane / index.spec.tsx View on Github external
fetchMock.mock('/api/videos/43/', deferred.promise);

    const { getByText, queryByText, rerender } = render(
      wrapInIntlProvider(
        wrapInRouter(
          ,
        ),
      ),
    );

    // DashboardVideoPane shows the video as PROCESSING
    getByText('Processing');
    getByText(
      'Your video is currently processing. This may take up to an hour. Please come back later.',
    );
    expect(fetchMock.called()).not.toBeTruthy();

    // First backend call: the video is still processing
    jest.advanceTimersByTime(1000 * 60 + 200);
    await act(async () =>
      deferred.resolve(JSON.stringify({ ...video, upload_state: PROCESSING })),
    );

    expect(fetchMock.lastCall()![0]).toEqual('/api/videos/43/');
    expect(fetchMock.lastCall()![1]!.headers).toEqual({
      Authorization: 'Bearer cool_token_m8',
    });
    getByText('Processing');
    getByText(
      'Your video is currently processing. This may take up to an hour. Please come back later.',
    );
github Huemul / trae / test / index.spec.js View on Github external
.then((res) => {
        expect(res).toMatchSnapshot();
        expect(fetchMock.called(url)).toBeTruthy();
        expect(fetchMock.lastUrl()).toBe(url);
        expect(fetchMock.lastOptions().method).toBe('get');
      });
    });
github panjiesw / frest / test / frest / Frest.ts View on Github external
frest.post('testpost', { body }).then((res) => {
				if (res) {
					expect(fetchMock.called('testpost')).toBe(true);
					expect(res.origin.status).toBe(200);
					return frest.create('testcreate');
				}
				return Promise.reject('testpost: no response returned');
			}).then((res) => {
				if (res) {
github openfun / richie / src / frontend / js / components / SearchSuggestField / index.spec.tsx View on Github external
await wait();
    expect(fetchMock.calls().length).toEqual(0);

    fireEvent.change(field, { target: { value: 'xyz' } });
    await wait();
    expect(
      fetchMock.called('/api/v1.0/levels/autocomplete/?query=xyz'),
    ).toEqual(false);
    expect(
      fetchMock.called('/api/v1.0/organizations/autocomplete/?query=xyz'),
    ).toEqual(true);
    expect(
      fetchMock.called('/api/v1.0/persons/autocomplete/?query=xyz'),
    ).toEqual(true);
    expect(
      fetchMock.called('/api/v1.0/subjects/autocomplete/?query=xyz'),
    ).toEqual(true);
  });
github manifoldco / ui / src / components / manifold-data-deprovision-button / manifold-data-deprovision-button.spec.ts View on Github external
it('[resource-label]: fetches ID', async () => {
      await setup({ resourceLabel: 'resource-label' });
      expect(fetchMock.called(`begin:${graphqlEndpoint}`)).toBe(true);
    });
github manifoldco / ui / src / utils / restFetch.spec.ts View on Github external
}).catch(result => {
      expect(fetchMock.called('path:/v1/test')).toBe(true);
      expect(result.message).toEqual(body.message);
    });
  });