wheresrhys / fetch-mock-jest

Jest wrapper for fetch-mock, a comprehensive stub for fetch

Home Page:http://www.wheresrhys.co.uk/fetch-mock/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

1th call to fetch should have had a URL of ... but was undefined

ErlanBazarov opened this issue · comments

commented

Here is my code:

await new Promise(resolve => setTimeout(resolve, 1000));
console.log("CALLS", fetchMock.mock.calls, fetchMock.mock.calls[1][1].method);
expect(fetchMock).toHaveFetchedTimes(3);
expect(fetchMock).toHaveNthPosted(
  1,
  `${API_HOST}/workouts`,
);

The last assertion is giving me the error "1th call to fetch should have had a URL of http://localhost:1111/workouts but was undefined":

The output from console.log:

CALLS [
[
  'http://localhost:1111/workouts',
  { credentials: 'same-origin', headers: [Object], method: 'GET' }
],
[
  'http://localhost:1111/workouts/',
  {
    credentials: 'same-origin',
    headers: [Object],
    method: 'POST',
    body: '{"id":1,"secondId":1}'
  }
],
[
  'http://localhost:1111/workouts/1',
  {
    credentials: 'same-origin',
    headers: [Object],
    method: 'PATCH',
    body: '{"name":"sample name"}'
  }
]
] POST