Keine Beschreibung

index.d.ts 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. // Generated by typings
  2. // Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/0a23a2055d6f8f40fd39b5c1368ba6232842a057/angularjs/angular-mocks.d.ts
  3. declare module "angular-mocks/ngMock" {
  4. var _: string;
  5. export = _;
  6. }
  7. declare module "angular-mocks/ngMockE2E" {
  8. var _: string;
  9. export = _;
  10. }
  11. declare module "angular-mocks/ngAnimateMock" {
  12. var _: string;
  13. export = _;
  14. }
  15. ///////////////////////////////////////////////////////////////////////////////
  16. // ngMock module (angular-mocks.js)
  17. ///////////////////////////////////////////////////////////////////////////////
  18. declare namespace angular {
  19. ///////////////////////////////////////////////////////////////////////////
  20. // AngularStatic
  21. // We reopen it to add the MockStatic definition
  22. ///////////////////////////////////////////////////////////////////////////
  23. interface IAngularStatic {
  24. mock: IMockStatic;
  25. }
  26. // see https://docs.angularjs.org/api/ngMock/function/angular.mock.inject
  27. interface IInjectStatic {
  28. (...fns: Function[]): any;
  29. (...inlineAnnotatedConstructor: any[]): any; // this overload is undocumented, but works
  30. strictDi(val?: boolean): void;
  31. }
  32. interface IMockStatic {
  33. // see https://docs.angularjs.org/api/ngMock/function/angular.mock.dump
  34. dump(obj: any): string;
  35. inject: IInjectStatic
  36. // see https://docs.angularjs.org/api/ngMock/function/angular.mock.module
  37. module: {
  38. (...modules: any[]): any;
  39. sharedInjector(): void;
  40. }
  41. // see https://docs.angularjs.org/api/ngMock/type/angular.mock.TzDate
  42. TzDate(offset: number, timestamp: number): Date;
  43. TzDate(offset: number, timestamp: string): Date;
  44. }
  45. ///////////////////////////////////////////////////////////////////////////
  46. // ExceptionHandlerService
  47. // see https://docs.angularjs.org/api/ngMock/service/$exceptionHandler
  48. // see https://docs.angularjs.org/api/ngMock/provider/$exceptionHandlerProvider
  49. ///////////////////////////////////////////////////////////////////////////
  50. interface IExceptionHandlerProvider extends IServiceProvider {
  51. mode(mode: string): void;
  52. }
  53. ///////////////////////////////////////////////////////////////////////////
  54. // TimeoutService
  55. // see https://docs.angularjs.org/api/ngMock/service/$timeout
  56. // Augments the original service
  57. ///////////////////////////////////////////////////////////////////////////
  58. interface ITimeoutService {
  59. flush(delay?: number): void;
  60. flushNext(expectedDelay?: number): void;
  61. verifyNoPendingTasks(): void;
  62. }
  63. ///////////////////////////////////////////////////////////////////////////
  64. // IntervalService
  65. // see https://docs.angularjs.org/api/ngMock/service/$interval
  66. // Augments the original service
  67. ///////////////////////////////////////////////////////////////////////////
  68. interface IIntervalService {
  69. flush(millis?: number): number;
  70. }
  71. ///////////////////////////////////////////////////////////////////////////
  72. // LogService
  73. // see https://docs.angularjs.org/api/ngMock/service/$log
  74. // Augments the original service
  75. ///////////////////////////////////////////////////////////////////////////
  76. interface ILogService {
  77. assertEmpty(): void;
  78. reset(): void;
  79. }
  80. interface ILogCall {
  81. logs: string[];
  82. }
  83. ///////////////////////////////////////////////////////////////////////////
  84. // ControllerService mock
  85. // see https://docs.angularjs.org/api/ngMock/service/$controller
  86. // This interface extends http://docs.angularjs.org/api/ng.$controller
  87. ///////////////////////////////////////////////////////////////////////////
  88. interface IControllerService {
  89. // Although the documentation doesn't state this, locals are optional
  90. <T>(controllerConstructor: new (...args: any[]) => T, locals?: any, bindings?: any): T;
  91. <T>(controllerConstructor: Function, locals?: any, bindings?: any): T;
  92. <T>(controllerName: string, locals?: any, bindings?: any): T;
  93. }
  94. ///////////////////////////////////////////////////////////////////////////
  95. // ComponentControllerService
  96. // see https://docs.angularjs.org/api/ngMock/service/$componentController
  97. ///////////////////////////////////////////////////////////////////////////
  98. interface IComponentControllerService {
  99. // TBinding is an interface exposed by a component as per John Papa's style guide
  100. // https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#accessible-members-up-top
  101. <T, TBinding>(componentName: string, locals: { $scope: IScope, [key: string]: any }, bindings?: TBinding, ident?: string): T;
  102. }
  103. ///////////////////////////////////////////////////////////////////////////
  104. // HttpBackendService
  105. // see https://docs.angularjs.org/api/ngMock/service/$httpBackend
  106. ///////////////////////////////////////////////////////////////////////////
  107. interface IHttpBackendService {
  108. /**
  109. * Flushes all pending requests using the trained responses.
  110. * @param count Number of responses to flush (in the order they arrived). If undefined, all pending requests will be flushed.
  111. */
  112. flush(count?: number): void;
  113. /**
  114. * Resets all request expectations, but preserves all backend definitions.
  115. */
  116. resetExpectations(): void;
  117. /**
  118. * Verifies that all of the requests defined via the expect api were made. If any of the requests were not made, verifyNoOutstandingExpectation throws an exception.
  119. */
  120. verifyNoOutstandingExpectation(): void;
  121. /**
  122. * Verifies that there are no outstanding requests that need to be flushed.
  123. */
  124. verifyNoOutstandingRequest(): void;
  125. /**
  126. * Creates a new request expectation.
  127. * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false.
  128. * Returns an object with respond method that controls how a matched request is handled.
  129. * @param method HTTP method.
  130. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
  131. * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation.
  132. * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
  133. * @param keys Array of keys to assign to regex matches in the request url.
  134. */
  135. expect(method: string, url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]) :mock.IRequestHandler;
  136. /**
  137. * Creates a new request expectation for DELETE requests.
  138. * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false.
  139. * Returns an object with respond method that controls how a matched request is handled.
  140. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url is as expected.
  141. * @param headers HTTP headers object to be compared with the HTTP headers in the request.
  142. * @param keys Array of keys to assign to regex matches in the request url.
  143. */
  144. expectDELETE(url: string | RegExp | ((url: string) => boolean), headers?: Object, keys?: Object[]): mock.IRequestHandler;
  145. /**
  146. * Creates a new request expectation for GET requests.
  147. * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false.
  148. * Returns an object with respond method that controls how a matched request is handled.
  149. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
  150. * @param headers HTTP headers object to be compared with the HTTP headers in the request.
  151. * @param keys Array of keys to assign to regex matches in the request url.
  152. */
  153. expectGET(url: string | RegExp | ((url: string) => boolean), headers?: Object, keys?: Object[]): mock.IRequestHandler;
  154. /**
  155. * Creates a new request expectation for HEAD requests.
  156. * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false.
  157. * Returns an object with respond method that controls how a matched request is handled.
  158. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
  159. * @param headers HTTP headers object to be compared with the HTTP headers in the request.
  160. * @param keys Array of keys to assign to regex matches in the request url.
  161. */
  162. expectHEAD(url: string | RegExp | ((url: string) => boolean), headers?: Object, keys?: Object[]): mock.IRequestHandler;
  163. /**
  164. * Creates a new request expectation for JSONP requests.
  165. * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, or if function returns false.
  166. * Returns an object with respond method that controls how a matched request is handled.
  167. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
  168. * @param keys Array of keys to assign to regex matches in the request url.
  169. */
  170. expectJSONP(url: string | RegExp | ((url: string) => boolean), keys?: Object[]): mock.IRequestHandler;
  171. /**
  172. * Creates a new request expectation for PATCH requests.
  173. * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false.
  174. * Returns an object with respond method that controls how a matched request is handled.
  175. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
  176. * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation.
  177. * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
  178. * @param keys Array of keys to assign to regex matches in the request url.
  179. */
  180. expectPATCH(url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object, keys?: Object[]): mock.IRequestHandler;
  181. /**
  182. * Creates a new request expectation for POST requests.
  183. * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false.
  184. * Returns an object with respond method that controls how a matched request is handled.
  185. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
  186. * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation.
  187. * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
  188. * @param keys Array of keys to assign to regex matches in the request url.
  189. */
  190. expectPOST(url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object, keys?: Object[]): mock.IRequestHandler;
  191. /**
  192. * Creates a new request expectation for PUT requests.
  193. * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false.
  194. * Returns an object with respond method that controls how a matched request is handled.
  195. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
  196. * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation.
  197. * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
  198. * @param keys Array of keys to assign to regex matches in the request url.
  199. */
  200. expectPUT(url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object, keys?: Object[]): mock.IRequestHandler;
  201. /**
  202. * Creates a new backend definition.
  203. * Returns an object with respond method that controls how a matched request is handled.
  204. * @param method HTTP method.
  205. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
  206. * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation.
  207. * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
  208. * @param keys Array of keys to assign to regex matches in the request url.
  209. */
  210. when(method: string, url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]): mock.IRequestHandler;
  211. /**
  212. * Creates a new backend definition for DELETE requests.
  213. * Returns an object with respond method that controls how a matched request is handled.
  214. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
  215. * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
  216. * @param keys Array of keys to assign to regex matches in the request url.
  217. */
  218. whenDELETE(url: string | RegExp | ((url: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]): mock.IRequestHandler;
  219. /**
  220. * Creates a new backend definition for GET requests.
  221. * Returns an object with respond method that controls how a matched request is handled.
  222. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
  223. * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
  224. * @param keys Array of keys to assign to regex matches in request url described above
  225. * @param keys Array of keys to assign to regex matches in the request url.
  226. */
  227. whenGET(url: string | RegExp | ((url: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]): mock.IRequestHandler;
  228. /**
  229. * Creates a new backend definition for HEAD requests.
  230. * Returns an object with respond method that controls how a matched request is handled.
  231. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
  232. * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
  233. * @param keys Array of keys to assign to regex matches in the request url.
  234. */
  235. whenHEAD(url: string | RegExp | ((url: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]): mock.IRequestHandler;
  236. /**
  237. * Creates a new backend definition for JSONP requests.
  238. * Returns an object with respond method that controls how a matched request is handled.
  239. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
  240. * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
  241. * @param keys Array of keys to assign to regex matches in the request url.
  242. */
  243. whenJSONP(url: string | RegExp | ((url: string) => boolean), keys?: Object[]): mock.IRequestHandler;
  244. /**
  245. * Creates a new backend definition for PATCH requests.
  246. * Returns an object with respond method that controls how a matched request is handled.
  247. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
  248. * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation.
  249. * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
  250. * @param keys Array of keys to assign to regex matches in the request url.
  251. */
  252. whenPATCH(url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]): mock.IRequestHandler;
  253. /**
  254. * Creates a new backend definition for POST requests.
  255. * Returns an object with respond method that controls how a matched request is handled.
  256. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
  257. * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation.
  258. * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
  259. * @param keys Array of keys to assign to regex matches in the request url.
  260. */
  261. whenPOST(url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]): mock.IRequestHandler;
  262. /**
  263. * Creates a new backend definition for PUT requests.
  264. * Returns an object with respond method that controls how a matched request is handled.
  265. * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
  266. * @param data HTTP request body string, json object, regular expression or function that receives the data and returns true if the data matches the current expectation.
  267. * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
  268. * @param keys Array of keys to assign to regex matches in the request url.
  269. */
  270. whenPUT(url: string | RegExp | ((url: string) => boolean), data?: string | RegExp | Object | ((data: string) => boolean), headers?: Object | ((object: Object) => boolean), keys?: Object[]): mock.IRequestHandler;
  271. }
  272. export module mock {
  273. // returned interface by the the mocked HttpBackendService expect/when methods
  274. interface IRequestHandler {
  275. /**
  276. * Controls the response for a matched request using a function to construct the response.
  277. * Returns the RequestHandler object for possible overrides.
  278. * @param func Function that receives the request HTTP method, url, data, headers, and an array of keys to regex matches in the request url and returns an array containing response status (number), data, headers, and status text.
  279. */
  280. respond(func: ((method: string, url: string, data: string | Object, headers: Object, params?: any) => [number, string | Object, Object, string])): IRequestHandler;
  281. /**
  282. * Controls the response for a matched request using supplied static data to construct the response.
  283. * Returns the RequestHandler object for possible overrides.
  284. * @param status HTTP status code to add to the response.
  285. * @param data Data to add to the response.
  286. * @param headers Headers object to add to the response.
  287. * @param responseText Response text to add to the response.
  288. */
  289. respond(status: number, data: string | Object, headers?: Object, responseText?: string): IRequestHandler;
  290. /**
  291. * Controls the response for a matched request using the HTTP status code 200 and supplied static data to construct the response.
  292. * Returns the RequestHandler object for possible overrides.
  293. * @param data Data to add to the response.
  294. * @param headers Headers object to add to the response.
  295. * @param responseText Response text to add to the response.
  296. */
  297. respond(data: string | Object, headers?: Object, responseText?: string): IRequestHandler;
  298. // Available when ngMockE2E is loaded
  299. /**
  300. * Any request matching a backend definition or expectation with passThrough handler will be passed through to the real backend (an XHR request will be made to the server.)
  301. */
  302. passThrough(): IRequestHandler;
  303. }
  304. }
  305. }
  306. ///////////////////////////////////////////////////////////////////////////////
  307. // functions attached to global object (window)
  308. ///////////////////////////////////////////////////////////////////////////////
  309. //Use `angular.mock.module` instead of `module`, as `module` conflicts with commonjs.
  310. //declare var module: (...modules: any[]) => any;
  311. declare var inject: angular.IInjectStatic;