티스토리 뷰
구현을 살펴보면 jest-fetch-mock
항상 약속이 해결 fetch
됩니다 catch
. 즉, . 그래서 당신은 a Promise.reject()
가 필요하고 당신의 테스트에서 당신은 다음과 같은 것을해야 할 것입니다.
it('handles fetch errors', () => {
return get('doesnotexist')
.catch(error => expect(error).toEqual('some error'));
});
-------------------유효하지 않은 본문을 주면 약속의 캐치 부분이 넘어갑니다.
fetch.mockResponseOnce(null, init);
출처
https://stackoverflow.com/questions/39920278