Nock

https://github.com/nock/nock

  • Allows ensuring that all requests are sent
  • Allows being more or less specific about each request; you can verify an exact request body or headers, or a match function, or ignore it
it('…', () => {
  const mockedServer = nock('http://localhost:3000')
        .get('/api/bookmarks?filter[read]=false&')
        .reply(200, jsonApiResponseBody([bookmark]))
        .patch('/api/bookmarks/1?', {
          data: {
            type: 'bookmarks',
            id: '1',
            attributes: {read: true},
          },
        })
        .reply(500)
        .patch('/api/bookmarks/1?')
        .reply(200);
  // test steps
 
  mockedServer.done();
});