-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Expand file tree
/
Copy pathapi.ts
More file actions
124 lines (111 loc) · 3.93 KB
/
api.ts
File metadata and controls
124 lines (111 loc) · 3.93 KB
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
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {HttpRequest} from '../../index';
import {TestRequest} from './request';
/**
* Defines a matcher for requests based on URL, method, or both.
*
* @publicApi
*/
export interface RequestMatch {
method?: string;
url?: string;
}
/**
* Controller to be injected into tests, that allows for mocking and flushing
* of requests.
*
* @publicApi
*/
export abstract class HttpTestingController {
/**
* Search for requests that match the given parameter, without any expectations.
*/
abstract match(
match: string | RequestMatch | ((req: HttpRequest<any>) => boolean),
): TestRequest[];
/**
* Expect that a single request has been made which matches the given URL, and return its
* mock.
*
* If no such request has been made, or more than one such request has been made, fail with an
* error message including the given request description, if any.
*/
abstract expectOne(url: string, description?: string): TestRequest;
/**
* Expect that a single request has been made which matches the given parameters, and return
* its mock.
*
* If no such request has been made, or more than one such request has been made, fail with an
* error message including the given request description, if any.
*/
abstract expectOne(params: RequestMatch, description?: string): TestRequest;
/**
* Expect that a single request has been made which matches the given predicate function, and
* return its mock.
*
* If no such request has been made, or more than one such request has been made, fail with an
* error message including the given request description, if any.
*/
abstract expectOne(
matchFn: (req: HttpRequest<any>) => boolean,
description?: string,
): TestRequest;
/**
* Expect that a single request has been made which matches the given condition, and return
* its mock.
*
* If no such request has been made, or more than one such request has been made, fail with an
* error message including the given request description, if any.
*/
abstract expectOne(
match: string | RequestMatch | ((req: HttpRequest<any>) => boolean),
description?: string,
): TestRequest;
/**
* Expect that no requests have been made which match the given URL.
*
* If a matching request has been made, fail with an error message including the given request
* description, if any.
*/
abstract expectNone(url: string, description?: string): void;
/**
* Expect that no requests have been made which match the given parameters.
*
* If a matching request has been made, fail with an error message including the given request
* description, if any.
*/
abstract expectNone(params: RequestMatch, description?: string): void;
/**
* Expect that no requests have been made which match the given predicate function.
*
* If a matching request has been made, fail with an error message including the given request
* description, if any.
*/
abstract expectNone(matchFn: (req: HttpRequest<any>) => boolean, description?: string): void;
/**
* Expect that no requests have been made which match the given condition.
*
* If a matching request has been made, fail with an error message including the given request
* description, if any.
*/
abstract expectNone(
match: string | RequestMatch | ((req: HttpRequest<any>) => boolean),
description?: string,
): void;
/**
* Verify that no unmatched requests are outstanding.
*
* If any requests are outstanding, fail with an error message indicating which requests were not
* handled.
*
* If `ignoreCancelled` is not set (the default), `verify()` will also fail if cancelled requests
* were not explicitly matched.
*/
abstract verify(opts?: {ignoreCancelled?: boolean}): void;
}