mentoss
Version:
A utility to mock fetch requests and responses.
47 lines (46 loc) • 1.96 kB
TypeScript
/**
* Represents a matcher for a request.
*/
export class RequestMatcher {
/**
* Creates a new instance.
* @param {object} options The options for the route.
* @param {string} options.method The method to match.
* @param {string} options.url The URL to match.
* @param {string} options.baseUrl The base URL to prepend to the url.
* @param {HttpBody} [options.body] The body to match.
* @param {Record<string, string>} [options.headers] The headers to match.
* @param {Record<string, string>} [options.query] The query string to match.
* @param {Record<string, string>} [options.params] The URL parameters to match.
*/
constructor({ method, url, baseUrl, body, headers, query, params, }: {
method: string;
url: string;
baseUrl: string;
body?: import("./types.js").HttpBody | undefined;
headers?: Record<string, string> | undefined;
query?: Record<string, string> | undefined;
params?: Record<string, string> | undefined;
});
/**
* Checks if the request matches the matcher. Traces all of the details to help
* with debugging.
* @param {RequestPattern} request The request to check.
* @returns {{matches:boolean, messages:string[], params:Record<string, string|undefined>, query:URLSearchParams}} True if the request matches, false if not.
*/
traceMatches(request: RequestPattern): {
matches: boolean;
messages: string[];
params: Record<string, string | undefined>;
query: URLSearchParams;
};
/**
* Checks if the request matches the matcher.
* @param {RequestPattern} request The request to check.
* @returns {boolean} True if the request matches, false if not.
*/
matches(request: RequestPattern): boolean;
#private;
}
export type RequestPattern = import("./types.js").RequestPattern;
export type HttpBody = import("./types.js").HttpBody;