3

I need to mock an fetch call which returns an array with Jest Fetch Mock:

https://jsonplaceholder.typicode.com/todos/

it ('<Main />', () => {
  const wrapper = render (<Main />);

  fetch.mockResponseOnce (
    JSON.stringify ([
      {
        id: '1',
        title: 'hi',
      },
    ])
  );

  wrapper.debug ();
});

However I'm getting an error:

(node:4667) UnhandledPromiseRejectionWarning: FetchError: invalid json response body at undefined reason: Unexpected end of JSON input
Evanss
  • 23,390
  • 94
  • 282
  • 505

0 Answers0