How to use the fetch-mock.calls 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 Palindrom / Palindrom / test / specs / client / reconnect.js View on Github external
xit(`should  send HTTP ping`, async () => {         
                    
                    await sleep(pingIntervalS*2*1000 + 10);
                    // ping
                    expect(fetchMock.calls('ping')).to.be.lengthOf.at.least(1, "expected `ping` to be fetched");
                }).timeout(pingIntervalS*3*1000);
            } else {
github Palindrom / Palindrom / test / specs / client / reconnect.js View on Github external
it('should send `HTTP PATCH _remoteUrl_/reconnect` with pending changes in body', async () => {
                    
                    await sleep(pingIntervalS*1000 + 10);
                    // establish
                    expect(fetchMock.calls('establish')).to.be.lengthOf(1, "expected `establish` to be fetched once");
                    expect(fetchMock.called(/testURL/)).to.be.ok;
                    
                    // reconnect
                    expect(fetchMock.calls('reconnect')).to.be.lengthOf(1, "expected `reconnect` to be fetched once");
                    const [reconnectURL, reconnectCall] = fetchMock.lastCall();
                    expect(reconnectURL).to.equal(getTestURL('testURL')+'/reconnect');
                    expect(reconnectCall).to.have.property('body','[[{"op":"replace","path":"/_ver#c$","value":1},{"op":"test","path":"/_ver#s"},{"op":"replace","path":"/hello","value":"OT"}]]');
                    expect(reconnectCall).to.have.property('method','PATCH');
                    expect(reconnectCall.headers).to.have.property('Content-Type','application/json-patch+json');
                    expect(reconnectCall.headers).to.have.property('Accept','application/json');
                }).timeout(pingIntervalS*2*1000);
                describe('when server responds to `/reconnect`', () => {
github Palindrom / Palindrom / test / specs / client / heartbeat.js View on Github external
it(`should send empty patch (\`[]\`) after ${pingIntervalS} seconds after sending local change`, async () => {

                // establish
                expect(fetchMock.calls('establish')).to.be.lengthOf(1);
                expect(fetchMock.called(/testURL/)).to.be.ok;
                
                await sleep(10);
                // change
                palindrom.obj.hello = "Ping Machine";
                await sleep(10);
                expect(fetchMock.calls('patch')).to.be.lengthOf(1, 'should send patch request just after a change');

                await sleep(pingIntervalS*1000 + 10);
                // // ping
                expect(fetchMock.calls('ping')).to.be.lengthOf(1, 'should send ping request `pingIntervalS` after a change');
                const [pingURL, pingCall] = fetchMock.lastCall();
                expect(pingURL).to.equal(getTestURL('testURL'));
                expect(pingCall).to.have.property('body','[]');
                expect(pingCall).to.have.property('method','PATCH');
                expect(pingCall.headers).to.have.property('Content-Type','application/json-patch+json');
                expect(pingCall.headers).to.have.property('Accept','application/json-patch+json');
                
            }).timeout(pingIntervalS*2*1000);
            describe('and server does not respond to send ping within `pingIntervalS`', () => {
github ylletjs / yllet / packages / client / __tests__ / Transport / index.spec.js View on Github external
it(`${verb} passes custom config`, () => {
      fetchMock.once(endpoint, {});
      transport.request(verb, endpoint, {}, config);
      expect(fetchMock.calls()[0][1]).toEqual(expected);
    });
  });
github wp-headless / fetch / packages / client / __tests__ / Transport / index.spec.js View on Github external
it('calls fetch() with correct input url', () => {
  const path = 'https://wp.com/wp-json/wp/v1/posts';
  fetchMock.once(path, {});
  transport.request(path);
  expect(fetchMock.calls()[0][0]).toEqual(path);
});
github badbatch / graphql-box / test / specs / browser / query / index.ts View on Github external
it("then the client should not have made a fetch request", () => {
              expect(fetchMock.calls().matched).to.have.lengthOf(0);
            });
          }
github badbatch / graphql-box / test / specs / server / query / index.ts View on Github external
it("then the client should have made no fetch request", () => {
            expect(fetchMock.calls().unmatched).to.have.lengthOf(0);
          });
github Rsullivan00 / apollo-link-json-api / src / __tests__ / jsonApiLink.ts View on Github external
post(id: "1") @jsonapi(path: "/post/{args.id}") {
            id
            title
          }
        }
      `;

      await makePromise(
        execute(link, {
          operationName: 'postTitle',
          query: postTitleQuery,
          variables: { id: '1' },
        }),
      );

      const requestCall = fetchMock.calls('/api/post/1')[0];
      expect(orderDupPreservingFlattenedHeaders(requestCall[1])).toEqual([
        'accept: application/vnd.api+json',
        'authorization: 1234',
        'context: context',
        'setup: setup, in-context duplicate setup',
      ]);
    });
github Rsullivan00 / apollo-link-json-api / src / __tests__ / jsonApiLink.ts View on Github external
operationName: 'posts',
        query: postsQuery,
      };

      const link1 = new JsonApiLink({ uri: '/api' });
      await makePromise(execute(link1, operation));

      const link2 = new JsonApiLink({
        uri: '/api',
        headers: {
          Accept: 'text/plain',
        },
      });
      await makePromise(execute(link2, operation));

      const requestCalls = fetchMock.calls('/api/posts');
      expect(orderDupPreservingFlattenedHeaders(requestCalls[0][1])).toEqual([
        'accept: application/vnd.api+json',
      ]);
      expect(orderDupPreservingFlattenedHeaders(requestCalls[1][1])).toEqual([
        'accept: text/plain',
      ]);
    });
github apache / incubator-superset / superset / assets / spec / javascripts / sqllab / actions / sqlLab_spec.js View on Github external
return makeRequest().then(() => {
        expect(fetchMock.calls(stopQueryEndpoint)).toHaveLength(1);
      });
    });