How to use the fetch-mock.mock 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 tungv / redux-api-call / packages / core / src / __tests__ / middleware.spec.js View on Github external
it('should dispatch FETCH_COMPLETE with a text object', async () => {
      const store = getStore();
      fetchMock.mock('http://localhost:3000/api/test', { body: 'string' });

      store.dispatch({
        type: ACTION_FETCH_START,
        payload: {
          requestedAt: 1478329954380,
          name: 'TEST_API',
          endpoint: 'http://localhost:3000/api/test',
        },
      });

      const [_, complete] = await takeActionsUntil(store, 2);

      expect(complete).toEqual({
        type: ACTION_FETCH_COMPLETE,
        payload: {
          name: 'TEST_API',
github Palindrom / Palindrom / test / specs / dom / index.js View on Github external
it('Morphing to a URL should dispatch the event after a successful request', async () => {
                        const rel = getTestURL('newUrl', true);

                        fetchMock.mock(rel, {
                            status: 200,
                            body: '{"hello": "world"}'
                        });

                        let firedEvent;

                        const handler = event => {
                            firedEvent = event;

                            window.removeEventListener(
                                'palindrom-after-redirect',
                                handler
                            );
                        };

                        window.addEventListener(
github Huemul / trae / test / trae / put.spec.js View on Github external
it('makes a PUT request to baseURL + path', () => {
    const url = `${TEST_URL}/foo`;

    fetchMock.mock(url, {
      status : 200,
      body   : {
        foo: 'bar'
      },
      headers: {
        'Content-Type': 'application/json'
      }
    }, {
      method: 'put'
    });

    const testTrae = trae.create();

    testTrae.before((c) => {
      expect(c.headers).toMatchSnapshot();
      return c;
github guardian / facia-tool / client-v2 / src / shared / actions / __tests__ / snapcards.spec.ts View on Github external
it('should be created if they are provided on the root path', async () => {
        const store = mockStore(initialState);
        const snapUrl =
          'https://gu.com?gu-snapType=json.html&gu-snapUri=https://interactive.guim.co.uk/atoms/2019/03/29/unmeaningful-vote/snap/snap.json';
        fetchMock.mock(snapUrl, JSON.stringify({}));
        await store.dispatch(createArticleEntitiesFromDrop(
          idDrop(snapUrl)
        ) as any);
        const actions = store.getActions();
        expect(actions[0]).toEqual(
          cardsReceived({
            card1: {
              frontPublicationDate: 1487076708000,
              id: 'snap/1487076708000',
              meta: {
                byline: undefined,
                trailText: undefined,
                showByline: false,
                snapType: 'json.html',
                snapUri:
                  'https://interactive.guim.co.uk/atoms/2019/03/29/unmeaningful-vote/snap/snap.json'
github Workfront / workfront-api / test / integration / create.spec.ts View on Github external
beforeEach(function() {
        fetchMock.mock(
            `begin:${API_URL}/attask/api`,
            fixture,
            {
                name: 'create'
            }
        )
    })
github pusher / pusher-js / spec / javascripts / unit / worker / pusher_authorizer_spec.js View on Github external
it("should pass headers in the request", function(){
    fetchMock
      .mock(endpoint, {body: {hello: "world"}});

    var headers = { "foo": "bar", "n": 42 };
    var authorizer = new Authorizer(
      { name: "chan" },
      { authTransport: "ajax",
        authEndpoint: endpoint,
        auth: {
          headers: headers
        }
      }
    );

    authorizer.authorize("1.23", function() {});

    var lastCall = fetchMock.lastCall(endpoint)[0];
github manifoldco / ui / src / components / manifold-resource-rename / manifold-resource-rename.spec.ts View on Github external
beforeEach(() => {
    fetchMock.mock('begin:https://analytics.manifold.co', 200);
    fetchMock.mock('begin:https://api.manifold.co', 200);
  });
github manifoldco / ui / src / components / manifold-resource-credentials / manifold-resource-credentials.spec.ts View on Github external
beforeEach(() => {
    fetchMock.mock('begin:https://analytics.manifold.co', 200);
    fetchMock.mock('begin:https://api.manifold.co', 200);
  });