index.d.ts 6.8 KB

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