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