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