UNPKG

hungry-fetch

Version:
44 lines (43 loc) 1.61 kB
/** * This monkeypatches fetch and stores all requests send with fetch. * fetch calls are simply resolved with no data. * * With this you can test what your code is sending via fetch. */ import FetchCall from './fetch-call'; export declare type Body = Record<string, any> | string; export declare type ResponseData = { pattern: string; body: Record<string, any> | string; config: { contentType?: string; headers?: { [key: string]: string; }; status?: number; }; resolve?: boolean; }; export declare function clear(): void; export declare function calls(): FetchCall[]; export declare function lastCall(): FetchCall; export declare function singleCall(): FetchCall; /** * Mock a response with a url matching the specified pattern. * * The pattern supports wildcards for parts of the url by using an asterisk (\*). * Example: /category/*&#47;details * * You may also use a single asterisk "*" to match all routes. * * The matchers are weighted so that a perfect match has the highest priority. * A match using wildcard components has the second highest prority. The * single asterisk matcher has the lowest priority. This helps to configure * default responses. * * @param urlMatcher The matcher incoming urls will be checked against. * @param body The body of the response. * @param config An optional config. * @param resolve Set to false to reject matching fetch calls. */ export declare function mockResponse(pattern: string, body: Body, config?: {}, resolve?: boolean): void;