How to use the fetch-mock.lastUrl 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 synyx / urlaubsverwaltung / src / main / webapp / js / __tests__ / fetch.spec.js View on Github external
it('posts given data as contentType=json', async () => {
      fetchMock.mock('https://awesome-stuff.com/api/post-something', {});

      await postJSON('https://awesome-stuff.com/api/post-something', {
        some: 'attributes'
      });

      expect(fetchMock.lastUrl()).toEqual('https://awesome-stuff.com/api/post-something');
      expect(fetchMock.lastOptions()).toEqual(expect.objectContaining({
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: '{"some":"attributes"}'
      }));
    });
github Palindrom / Palindrom / test / specs / dom / index.js View on Github external
window.addEventListener(
                            'palindrom-before-redirect',
                            handler
                        );

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

                        await palindrom.morphUrl('/newUrl');

                        await sleep();

                        assert.equal(firedEvent.detail.href, '/newUrl');
                        expect(fetchMock.lastUrl()).to.equal('/newUrl');
                        expect(window.location.pathname).to.equal(
                            '/newUrl'
                        );
                    });
                    it('Morphing to a URL should NOT issue a request after a canceled event and morphUrl\'s retuned promise should resolve to `false`', async () => {
github apollographql / apollo-client / src / link / http / __tests__ / HttpLink.ts View on Github external
makeCallback(done, result => {
          const uri = fetchMock.lastUrl();
          expect(fetchMock.lastUrl()).toBe('/dataFunc');
        }),
      );
github Huemul / trae / test / trae / patch.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('PATCH');
    });
  });
github Huemul / trae / test / trae / put.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('PUT');
    });
  });
github apollographql / apollo-client / src / link / http / __tests__ / HttpLink.ts View on Github external
makeCallback(done, result => {
          const uri = fetchMock.lastUrl();
          expect(fetchMock.lastUrl()).toBe('/dataFunc');
        }),
      );
github Huemul / trae / test / trae / head.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('HEAD');
    });
  });
github apollographql / apollo-link / packages / apollo-link-http / src / __tests__ / sharedHttpTests.ts View on Github external
makeCallback(done, result => {
          const uri = fetchMock.lastUrl();
          expect(uri).toBe('data');
        }),
      );
github Huemul / trae / test / trae / post.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('POST');
    });
  });