nock
Version:
HTTP server mocking and expectations library for Node.js
60 lines (59 loc) • 2.96 kB
TypeScript
import type { ReplyBody, ReplyHeaders, RequestBodyMatcher, RequestHeaderMatcher } from './interceptor.ts';
export interface Options {
allowUnmocked?: boolean;
reqheaders?: Record<string, RequestHeaderMatcher>;
badheaders?: string[];
conditionally?: () => boolean;
filteringScope?: (scope: string) => boolean;
encodedQueryParams?: boolean;
}
export interface Definition {
scope: string | RegExp;
path: string | RegExp;
port?: number | string;
method?: string;
status?: number;
body?: RequestBodyMatcher;
reply?: string;
reqheaders?: Record<string, RequestHeaderMatcher>;
badheaders?: string[];
rawHeaders?: ReplyHeaders;
response?: ReplyBody;
responseIsBinary?: boolean;
headers?: ReplyHeaders;
options?: Options;
}
import { EventEmitter } from 'node:events';
import { Interceptor } from './interceptor.ts';
declare class Scope extends EventEmitter {
constructor(basePath: string | RegExp | URL, options?: Options);
add(key: string, interceptor: Interceptor): void;
remove(key: string, interceptor: Interceptor): void;
intercept(uri: string | RegExp | ((path: string) => boolean), method: string, requestBody?: RequestBodyMatcher, interceptorOptions?: Options): Interceptor;
get(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
post(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
put(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
head(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
patch(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
merge(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
delete(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
options(uri: string | RegExp | ((path: string) => boolean), requestBody?: RequestBodyMatcher, options?: Options): Interceptor;
pendingMocks(): string[];
activeMocks(): string[];
isDone(): boolean;
done(): void;
buildFilter(): any;
filteringPath(): this;
filteringRequestBody(): this;
matchHeader(name: string, value: RequestHeaderMatcher): this;
defaultReplyHeaders(headers: ReplyHeaders): this;
persist(flag?: boolean): this;
shouldPersist(): boolean;
replyContentLength(): this;
replyDate(d?: Date): this;
clone(): Scope;
}
declare function loadDefs(path: string): any;
declare function load(path: string): Scope[];
declare function define(nockDefs: Record<string, any>[]): Scope[];
export { Scope, load, loadDefs, define };