index.d.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /**
  2. * @license Angular v16.2.9
  3. * (c) 2010-2022 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import { HttpEvent } from '@angular/common/http';
  7. import { HttpHeaders } from '@angular/common/http';
  8. import { HttpRequest } from '@angular/common/http';
  9. import * as i0 from '@angular/core';
  10. import * as i1 from '@angular/common/http';
  11. import { Observer } from 'rxjs';
  12. import { Provider } from '@angular/core';
  13. /**
  14. * Configures `HttpClientTestingBackend` as the `HttpBackend` used by `HttpClient`.
  15. *
  16. * Inject `HttpTestingController` to expect and flush requests in your tests.
  17. *
  18. * @publicApi
  19. */
  20. export declare class HttpClientTestingModule {
  21. static ɵfac: i0.ɵɵFactoryDeclaration<HttpClientTestingModule, never>;
  22. static ɵmod: i0.ɵɵNgModuleDeclaration<HttpClientTestingModule, never, [typeof i1.HttpClientModule], never>;
  23. static ɵinj: i0.ɵɵInjectorDeclaration<HttpClientTestingModule>;
  24. }
  25. /**
  26. * Controller to be injected into tests, that allows for mocking and flushing
  27. * of requests.
  28. *
  29. * @publicApi
  30. */
  31. export declare abstract class HttpTestingController {
  32. /**
  33. * Search for requests that match the given parameter, without any expectations.
  34. */
  35. abstract match(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean)): TestRequest[];
  36. /**
  37. * Expect that a single request has been made which matches the given URL, and return its
  38. * mock.
  39. *
  40. * If no such request has been made, or more than one such request has been made, fail with an
  41. * error message including the given request description, if any.
  42. */
  43. abstract expectOne(url: string, description?: string): TestRequest;
  44. /**
  45. * Expect that a single request has been made which matches the given parameters, and return
  46. * its mock.
  47. *
  48. * If no such request has been made, or more than one such request has been made, fail with an
  49. * error message including the given request description, if any.
  50. */
  51. abstract expectOne(params: RequestMatch, description?: string): TestRequest;
  52. /**
  53. * Expect that a single request has been made which matches the given predicate function, and
  54. * return its mock.
  55. *
  56. * If no such request has been made, or more than one such request has been made, fail with an
  57. * error message including the given request description, if any.
  58. */
  59. abstract expectOne(matchFn: ((req: HttpRequest<any>) => boolean), description?: string): TestRequest;
  60. /**
  61. * Expect that a single request has been made which matches the given condition, and return
  62. * its mock.
  63. *
  64. * If no such request has been made, or more than one such request has been made, fail with an
  65. * error message including the given request description, if any.
  66. */
  67. abstract expectOne(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean), description?: string): TestRequest;
  68. /**
  69. * Expect that no requests have been made which match the given URL.
  70. *
  71. * If a matching request has been made, fail with an error message including the given request
  72. * description, if any.
  73. */
  74. abstract expectNone(url: string, description?: string): void;
  75. /**
  76. * Expect that no requests have been made which match the given parameters.
  77. *
  78. * If a matching request has been made, fail with an error message including the given request
  79. * description, if any.
  80. */
  81. abstract expectNone(params: RequestMatch, description?: string): void;
  82. /**
  83. * Expect that no requests have been made which match the given predicate function.
  84. *
  85. * If a matching request has been made, fail with an error message including the given request
  86. * description, if any.
  87. */
  88. abstract expectNone(matchFn: ((req: HttpRequest<any>) => boolean), description?: string): void;
  89. /**
  90. * Expect that no requests have been made which match the given condition.
  91. *
  92. * If a matching request has been made, fail with an error message including the given request
  93. * description, if any.
  94. */
  95. abstract expectNone(match: string | RequestMatch | ((req: HttpRequest<any>) => boolean), description?: string): void;
  96. /**
  97. * Verify that no unmatched requests are outstanding.
  98. *
  99. * If any requests are outstanding, fail with an error message indicating which requests were not
  100. * handled.
  101. *
  102. * If `ignoreCancelled` is not set (the default), `verify()` will also fail if cancelled requests
  103. * were not explicitly matched.
  104. */
  105. abstract verify(opts?: {
  106. ignoreCancelled?: boolean;
  107. }): void;
  108. }
  109. export declare function provideHttpClientTesting(): Provider[];
  110. /**
  111. * Defines a matcher for requests based on URL, method, or both.
  112. *
  113. * @publicApi
  114. */
  115. export declare interface RequestMatch {
  116. method?: string;
  117. url?: string;
  118. }
  119. /**
  120. * A mock requests that was received and is ready to be answered.
  121. *
  122. * This interface allows access to the underlying `HttpRequest`, and allows
  123. * responding with `HttpEvent`s or `HttpErrorResponse`s.
  124. *
  125. * @publicApi
  126. */
  127. export declare class TestRequest {
  128. request: HttpRequest<any>;
  129. private observer;
  130. /**
  131. * Whether the request was cancelled after it was sent.
  132. */
  133. get cancelled(): boolean;
  134. constructor(request: HttpRequest<any>, observer: Observer<HttpEvent<any>>);
  135. /**
  136. * Resolve the request by returning a body plus additional HTTP information (such as response
  137. * headers) if provided.
  138. * If the request specifies an expected body type, the body is converted into the requested type.
  139. * Otherwise, the body is converted to `JSON` by default.
  140. *
  141. * Both successful and unsuccessful responses can be delivered via `flush()`.
  142. */
  143. flush(body: ArrayBuffer | Blob | boolean | string | number | Object | (boolean | string | number | Object | null)[] | null, opts?: {
  144. headers?: HttpHeaders | {
  145. [name: string]: string | string[];
  146. };
  147. status?: number;
  148. statusText?: string;
  149. }): void;
  150. /**
  151. * Resolve the request by returning an `ErrorEvent` (e.g. simulating a network failure).
  152. * @deprecated Http requests never emit an `ErrorEvent`. Please specify a `ProgressEvent`.
  153. */
  154. error(error: ErrorEvent, opts?: TestRequestErrorOptions): void;
  155. /**
  156. * Resolve the request by returning an `ProgressEvent` (e.g. simulating a network failure).
  157. */
  158. error(error: ProgressEvent, opts?: TestRequestErrorOptions): void;
  159. /**
  160. * Deliver an arbitrary `HttpEvent` (such as a progress event) on the response stream for this
  161. * request.
  162. */
  163. event(event: HttpEvent<any>): void;
  164. }
  165. /**
  166. * Type that describes options that can be used to create an error
  167. * in `TestRequest`.
  168. */
  169. declare type TestRequestErrorOptions = {
  170. headers?: HttpHeaders | {
  171. [name: string]: string | string[];
  172. };
  173. status?: number;
  174. statusText?: string;
  175. };
  176. export { }