index.d.ts 6.8 KB

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