如何使用jest-fetch-mock返回数组?

时间:2019-01-17 13:05:45

标签: jest-fetch-mock

我需要模拟一个提取调用,该调用返回带有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

0 个答案:

没有答案