@rocketmakers/api-swr
Version:
Rocketmakers front-end library for parsing a generated Typescript API client into a set of configurable React hooks for fetching and mutating data.
48 lines (47 loc) • 1.69 kB
TypeScript
import { AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders } from 'axios';
/**
* Interface for the parameters required to create a mock Axios response.
*/
interface MockResponseParams<T> {
/**
* The data to include in the response.
*/
data: T;
/**
* The status code for the response. Defaults to 200.
*/
status?: number;
/**
* The status text for the response. Defaults to 'OK'.
*/
statusText?: string;
/**
* The headers for the response. Defaults to an empty object.
*/
headers?: AxiosResponseHeaders;
/**
* The config for the response. Defaults to an empty object.
*/
config?: AxiosRequestConfig;
}
/**
* Creates a mock Axios response.
* @returns An AxiosResponse with the provided parameters.
*/
export declare const createMockAxiosResponse: <T>({ data, status, statusText, headers, config, }: MockResponseParams<T>) => AxiosResponse<T, any>;
/**
* Creates a successful mock Axios response.
*
* @param data - The data to include in the response.
* @param status - The status code for the response. Defaults to 200.
*
* @returns An AxiosResponse with a status of 200 (or the provided status) and the provided data.
*/
export declare const createMockAxiosSuccessResponse: <T>(data: T, status?: number) => AxiosResponse<T, any>;
/**
* Creates an error mock Axios response.
* @param status - The status code for the response. Defaults to 500.
* @returns An AxiosResponse with a status of 500 (or the provided status) and an empty data object.
*/
export declare const createMockAxiosErrorResponse: <T>(status?: number, statusText?: string) => AxiosResponse<T, any>;
export {};