3

我需要模拟一个 fetch 调用,它返回一个带有 Jest Fetch Mock 的数组:

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

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

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

  wrapper.debug ();
});

但是我收到一个错误:

(node:4667) UnhandledPromiseRejectionWarning: FetchError: invalid json response body at undefined reason: Unexpected end of JSON input
4

0 回答 0