UNPKG

@warp-drive/holodeck

Version:

⚡️ Simple, Fast HTTP Mocking for Tests

66 lines (65 loc) 2.16 kB
/** * @public */ export interface Scaffold { status: number; statusText?: string; headers: Record<string, string>; body: Record<string, string> | string | null; method: string; url: string; response: Record<string, unknown>; } /** * @public */ export type ScaffoldGenerator = () => Scaffold; /** * @public */ export type ResponseGenerator = () => Record<string, unknown>; /** * Sets up Mocking for a GET request on the mock server * for the supplied url. * * The response body is generated by the supplied response function. * * Available options: * - status: the status code to return (default: 200) * - headers: the headers to return (default: {}) * - body: the body to match against for the request (default: null) * - RECORD: whether to record the request (default: false) * * @param url the url to mock, relative to the mock server host (e.g. `users/1`) * @param response a function which generates the response to return * @param options status, headers for the response, body to match against for the request, and whether to record the request * @return */ export declare function GET(owner: object, url: string, response: ResponseGenerator, options?: Partial<Omit<Scaffold, "response" | "url" | "method">> & { RECORD?: boolean; }): Promise<void>; /** * Mock a POST request */ export declare function POST(owner: object, url: string, response: ResponseGenerator, options?: Partial<Omit<Scaffold, "response" | "url" | "method">> & { RECORD?: boolean; }): Promise<void>; /** * mock a PUT request */ export declare function PUT(owner: object, url: string, response: ResponseGenerator, options?: Partial<Omit<Scaffold, "response" | "url" | "method">> & { RECORD?: boolean; }): Promise<void>; /** * mock a PATCH request * */ export declare function PATCH(owner: object, url: string, response: ResponseGenerator, options?: Partial<Omit<Scaffold, "response" | "url" | "method">> & { RECORD?: boolean; }): Promise<void>; /** * mock a DELETE request */ export declare function DELETE(owner: object, url: string, response: ResponseGenerator, options?: Partial<Omit<Scaffold, "response" | "url" | "method">> & { RECORD?: boolean; }): Promise<void>;