forked from typed-typings/npm-nock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
130 lines (104 loc) · 4.1 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { EventEmitter } from 'events'
declare function nock (host: string | RegExp, options?: nock.Options): nock.Scope;
declare namespace nock {
export let back: NockBack;
export let emitter: EventEmitter;
export let recorder: Recorder;
// Nock Back interface: https://github.com/pgte/nock#nock-back.
// TODO(blakeembrey): Requires help finishing.
export interface NockBack {
(path: string, cb: (nockDone: () => void) => any): void;
fixtures: string;
setMode (mode: string): void;
currentMode: string;
}
export interface Recorder {
rec(capture?: boolean): void;
rec(options?: RecorderOptions): void;
play(): any[];
}
export interface Options {
allowUnmocked?: boolean;
reqheaders?: { [key: string]: any };
}
export interface RecorderOptions {
dont_print?: boolean;
output_objects?: boolean;
enable_reqheaders_recording?: boolean;
logging?: (message: string) => any;
use_separator?: boolean;
}
/**
* Restore the HTTP interceptor to the normal unmocked behaviour.
*/
export function restore (): void;
/**
* Cleanup all the prepared mocks (could be useful to cleanup some state after a failed test).
*/
export function cleanAll (): void;
/**
* You can call `isDone()` on a single expectation to determine if the expectation was met.
*/
export function isDone (): boolean;
/**
* This allows removing a specific interceptor for a url. It's useful when there's a list of common interceptors but one test requires one of them to behave differently.
*/
export function removeInterceptor (data: {
hostname: string;
path: string;
method?: string;
proto?: string;
}): void;
/**
* If a scope is not done, you can inspect the scope to infer which ones are still pending using the `scope.pendingMocks()` function.
*/
export function pendingMocks (): Object[];
/**
* By default, if you do not mock a host, a real HTTP request will do, but sometimes you should not permit real HTTP request.
*/
export function disableNetConnect (): void;
/**
* For enabling real HTTP requests.
*/
export function enableNetConnect (hostname?: string | RegExp): void;
// TODO(blakeembrey): Complete typings here.
export function load (pathToJson: string): Object[];
export function loadDefs (pathToJson: string): Object[];
export function define (nockDefs: Object[]): Object[];
export interface Scope {
intercept (path: string, verb: string, requestBody?: string, options?: any): Scope;
get (path: string | RegExp): Scope;
post (path: string | RegExp, body?: string | Object | RegExp): Scope;
put (path: string | RegExp, body?: string | Object | RegExp): Scope;
head (path: string | RegExp, body?: string | Object | RegExp): Scope;
patch (path: string | RegExp, body?: string | Object | RegExp): Scope;
merge (path: string | RegExp, body?: string | Object | RegExp): Scope;
delete (path: string | RegExp, body?: string | Object | RegExp): Scope;
pendingMocks (): Object[];
done (): void;
isDone (): boolean;
filteringPath (regex: RegExp, replace: string): Scope;
filteringPath (fn: (path: string) => string): Scope;
filteringRequestBody (regex: RegExp, replace: string): Scope;
filteringRequestBody (fn: (path: string) => string): Scope;
defaultReplyHeaders (headers: Object): Scope;
matchHeader (name: string, value: string | RegExp): Scope;
matchHeader (name: string, fn: (value: string) => boolean): Scope;
log (fn: (message: string) => any): Scope;
persist (): Scope;
replyContentLength (): Scope;
replyDate (date: Date): Scope;
delay (time: number | { head: number; body: number }): Scope;
delayConnection (timeMs: number): Scope;
query (params: any): Scope;
query (acceptAnyParams: boolean): Scope;
reply (statusCode: number, body?: string | Object, headers?: Object): Scope;
replyWithFile (statusCode: number, fileName: string): Scope;
replyWithError (error: string | Object): Scope;
times (repeats: number): Scope;
once (): Scope;
twice (): Scope;
thrice (): Scope;
}
}
export = nock;