UNPKG

2.84 kBTypeScriptView Raw
1interface JasmineAjaxResponse {
2 status?: number | undefined;
3 statusText?: string | undefined;
4 responseText?: string | undefined;
5 response?: string | undefined;
6 responseURL?: string | undefined;
7 responseJSON?: any;
8 contentType?: string | undefined;
9 responseHeaders?: { [key: string]: string } | undefined;
10}
11
12interface JasmineAjaxRequest extends XMLHttpRequest {
13 url: string;
14 method: string;
15 params: any;
16 username: string;
17 password: string;
18 requestHeaders: { [key: string]: string };
19 overriddenMimeType: string;
20 data(): string | object;
21
22 respondWith(response: JasmineAjaxResponse): void;
23 responseTimeout(): void;
24 responseError(options?: JasmineAjaxRequestStubErrorOptions): void;
25}
26
27interface JasmineAjaxRequestTracker {
28 track(request: JasmineAjaxRequest): void;
29 first(): JasmineAjaxRequest;
30 count(): number;
31 reset(): void;
32 mostRecent(): JasmineAjaxRequest;
33 at(index: number): JasmineAjaxRequest;
34 filter(urlToMatch: RegExp): JasmineAjaxRequest[];
35 filter(urlToMatch: (request: JasmineAjaxRequest) => boolean): JasmineAjaxRequest[];
36 filter(urlToMatch: string): JasmineAjaxRequest[];
37}
38
39/**
40 * @deprecated Use JasmineAjaxResponse instead
41 */
42type JasmineAjaxRequestStubReturnOptions = JasmineAjaxResponse;
43
44interface JasmineAjaxRequestStubErrorOptions {
45 status?: number | undefined;
46 statusText?: string | undefined;
47}
48
49interface JasmineAjaxRequestStub {
50 url: RegExp | string;
51 query: string;
52 data: string;
53 method: string;
54 andReturn(options: JasmineAjaxResponse): void;
55 andError(options: JasmineAjaxRequestStubErrorOptions): void;
56 andTimeout(): void;
57 andCallFunction(functionToCall: (request: JasmineAjaxRequest) => void): void;
58 matches(fullUrl: string, data: string, method: string): boolean;
59}
60
61interface JasmineAjaxStubTracker {
62 addStub(stub: JasmineAjaxRequestStub): void;
63 reset(): void;
64 findStub(url: string, data?: string, method?: string): JasmineAjaxRequestStub;
65}
66
67interface JasmineAjaxParamParser {
68 test(xhr: XMLHttpRequest): boolean;
69 parse(paramString: string): any;
70}
71
72declare class MockAjax {
73 constructor(globals: any);
74
75 install(): void;
76 uninstall(): void;
77
78 withMock(closure: () => void): void;
79 addCustomParamParser(parser: JasmineAjaxParamParser): void;
80
81 stubRequest(url: RegExp, data?: string, method?: string): JasmineAjaxRequestStub;
82 stubRequest(url: string, data?: string, method?: string): JasmineAjaxRequestStub;
83
84 stubRequest(url: RegExp, data?: RegExp, method?: string): JasmineAjaxRequestStub;
85 stubRequest(url: string, data?: RegExp, method?: string): JasmineAjaxRequestStub;
86
87 requests: JasmineAjaxRequestTracker;
88 stubs: JasmineAjaxStubTracker;
89}
90
91declare namespace jasmine {
92 const Ajax: MockAjax;
93}