declare type Fetch = ( url : string , options : RequestInit ) => Promise < Response > ; interface MockedFetch extends Fetch { mockRestore : ( ) => void ; } declare global { namespace NodeJS { interface Global { fetch : MockedFetch ; } } } export const getMockResponse = ( mockResponseData = { } , responseConfig = { status : 200 } ) => new Response ( JSON . stringify ( mockResponseData ) , responseConfig ) ; export const mockFetch = ( response = getMockResponse ( ) ) => { jest . spyOn ( global , 'fetch' ) . mockImplementation ( ( ) => Promise . resolve ( response ) ) ; } ; export const getMockFetch = ( ) => global . fetch ; export const restoreMockFetch = ( ) => { global . fetch . mockRestore ( ) ; } ;