UNPKG

36.1 kBTypeScriptView Raw
1/// <reference path="mocks.d.ts" />
2
3import * as angular from "angular";
4
5///////////////////////////////////////////////////////////////////////////////
6// ngMock module (angular-mocks.js)
7///////////////////////////////////////////////////////////////////////////////
8declare module "angular" {
9 ///////////////////////////////////////////////////////////////////////////
10 // AngularStatic
11 // We reopen it to add the MockStatic definition
12 ///////////////////////////////////////////////////////////////////////////
13 interface IAngularStatic {
14 mock: IMockStatic;
15 }
16
17 // see https://docs.angularjs.org/api/ngMock/function/angular.mock.inject
18 // Depending on context, it might return a function, however having `void | (() => void)`
19 // as a return type seems to be not useful. E.g. it requires type assertions in `beforeEach(inject(...))`.
20 interface IInjectStatic {
21 (...fns: Array<Injectable<(...args: any[]) => void>>): any; // void | (() => void);
22 strictDi(val?: boolean): any; // void | (() => void);
23 }
24
25 interface IMockStatic {
26 // see https://docs.angularjs.org/api/ngMock/function/angular.mock.dump
27 dump(obj: any): string;
28
29 inject: IInjectStatic;
30
31 // see https://docs.angularjs.org/api/ngMock/function/angular.mock.module
32 module: {
33 (...modules: any[]): any;
34 sharedInjector(): void;
35 };
36
37 // see https://docs.angularjs.org/api/ngMock/type/angular.mock.TzDate
38 TzDate(offset: number, timestamp: number | string): Date;
39 }
40
41 ///////////////////////////////////////////////////////////////////////////
42 // ExceptionHandlerService
43 // see https://docs.angularjs.org/api/ngMock/service/$exceptionHandler
44 // see https://docs.angularjs.org/api/ngMock/provider/$exceptionHandlerProvider
45 ///////////////////////////////////////////////////////////////////////////
46 interface IExceptionHandlerProvider extends IServiceProvider {
47 mode(mode: string): void;
48 }
49
50 ///////////////////////////////////////////////////////////////////////////
51 // TimeoutService
52 // see https://docs.angularjs.org/api/ngMock/service/$timeout
53 // Augments the original service
54 ///////////////////////////////////////////////////////////////////////////
55 interface ITimeoutService {
56 /**
57 * **Deprecated** since version 1.7.3. (Use `$flushPendingTasks` instead.)
58 *
59 * ---
60 * Flushes the queue of pending tasks.
61 *
62 * _This method is essentially an alias of `$flushPendingTasks`._
63 *
64 * > For historical reasons, this method will also flush non-`$timeout` pending tasks, such as
65 * > `$q` promises and tasks scheduled via `$applyAsync` and `$evalAsync`.
66 *
67 * @param delay - The maximum timeout amount to flush up until.
68 */
69 flush(delay?: number): void;
70
71 /**
72 * **Deprecated** since version 1.7.3. (Use `$verifyNoPendingTasks` instead.)
73 *
74 * ---
75 * Verifies that there are no pending tasks that need to be flushed. It throws an error if there
76 * are still pending tasks.
77 *
78 * _This method is essentially an alias of `$verifyNoPendingTasks` (called with no arguments)._
79 *
80 * > For historical reasons, this method will also verify non-`$timeout` pending tasks, such as
81 * > pending `$http` requests, in-progress `$route` transitions, unresolved `$q` promises and
82 * > tasks scheduled via `$applyAsync` and `$evalAsync`.
83 * >
84 * > It is recommended to use `$verifyNoPendingTasks` instead, which additionally supports
85 * > verifying a specific type of tasks. For example, you can verify there are no pending
86 * > timeouts with `$verifyNoPendingTasks('$timeout')`.
87 */
88 verifyNoPendingTasks(): void;
89 }
90
91 ///////////////////////////////////////////////////////////////////////////
92 // IntervalService
93 // see https://docs.angularjs.org/api/ngMock/service/$interval
94 // Augments the original service
95 ///////////////////////////////////////////////////////////////////////////
96 interface IIntervalService {
97 /**
98 * Runs interval tasks scheduled to be run in the next `millis` milliseconds.
99 *
100 * @param millis - The maximum timeout amount to flush up until.
101 * @return The amount of time moved forward.
102 */
103 flush(millis: number): number;
104 }
105
106 ///////////////////////////////////////////////////////////////////////////
107 // LogService
108 // see https://docs.angularjs.org/api/ngMock/service/$log
109 // Augments the original service
110 ///////////////////////////////////////////////////////////////////////////
111 interface ILogService {
112 assertEmpty(): void;
113 reset(): void;
114 }
115
116 interface ILogCall {
117 logs: string[];
118 }
119
120 ///////////////////////////////////////////////////////////////////////////
121 // ControllerService mock
122 // see https://docs.angularjs.org/api/ngMock/service/$controller
123 // This interface extends http://docs.angularjs.org/api/ng.$controller
124 ///////////////////////////////////////////////////////////////////////////
125 interface IControllerService {
126 // Although the documentation doesn't state this, locals are optional
127 <T>(
128 controllerConstructor: (new(...args: any[]) => T) | ((...args: any[]) => T) | string,
129 locals?: any,
130 bindings?: any,
131 ): T;
132 }
133
134 ///////////////////////////////////////////////////////////////////////////
135 // ComponentControllerService
136 // see https://docs.angularjs.org/api/ngMock/service/$componentController
137 ///////////////////////////////////////////////////////////////////////////
138 interface IComponentControllerService {
139 // TBinding is an interface exposed by a component as per John Papa's style guide
140 // https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#accessible-members-up-top
141 <T, TBinding>(
142 componentName: string,
143 locals: { $scope?: IScope | undefined; [key: string]: any },
144 bindings?: TBinding,
145 ident?: string,
146 ): T;
147 }
148
149 ///////////////////////////////////////////////////////////////////////////
150 // HttpBackendService
151 // see https://docs.angularjs.org/api/ngMock/service/$httpBackend
152 ///////////////////////////////////////////////////////////////////////////
153 interface IHttpBackendService {
154 /**
155 * Flushes pending requests using the trained responses. Requests are flushed in the order they
156 * were made, but it is also possible to skip one or more requests (for example to have them
157 * flushed later). This is useful for simulating scenarios where responses arrive from the server
158 * in any order.
159 *
160 * If there are no pending requests to flush when the method is called, an exception is thrown (as
161 * this is typically a sign of programming error).
162 *
163 * @param count Number of responses to flush. If undefined/null, all pending requests (starting
164 * after `skip`) will be flushed.
165 * @param skip Number of pending requests to skip. For example, a value of 5 would skip the first 5 pending requests and start flushing from the 6th onwards. _(default: 0)_
166 */
167 flush(count?: number, skip?: number): void;
168
169 /**
170 * Resets all request expectations, but preserves all backend definitions.
171 */
172 resetExpectations(): void;
173
174 /**
175 * Verifies that all of the requests defined via the `expect` api were made. If any of the
176 * requests were not made, verifyNoOutstandingExpectation throws an exception.
177 * @param digest Do digest before checking expectation. Pass anything except false to trigger digest.
178 * NOTE: this flag is purposely undocumented by Angular, which means it's not to be used in normal client code.
179 */
180 verifyNoOutstandingExpectation(digest?: boolean): void;
181
182 /**
183 * Verifies that there are no outstanding requests that need to be flushed.
184 */
185 verifyNoOutstandingRequest(): void;
186
187 /**
188 * Creates a new request expectation.
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 method HTTP method.
192 * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
193 * @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.
194 * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
195 * @param keys Array of keys to assign to regex matches in the request url.
196 */
197 expect(
198 method: string,
199 url: string | RegExp | ((url: string) => boolean),
200 data?: string | RegExp | object | ((data: string) => boolean),
201 headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean),
202 keys?: string[],
203 ): mock.IRequestHandler;
204
205 /**
206 * Creates a new request expectation for DELETE 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 is as expected.
210 * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
211 * @param keys Array of keys to assign to regex matches in the request url.
212 */
213 expectDELETE(
214 url: string | RegExp | ((url: string) => boolean),
215 headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean),
216 keys?: string[],
217 ): mock.IRequestHandler;
218
219 /**
220 * Creates a new request expectation for GET requests.
221 * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false.
222 * Returns an object with respond method that controls how a matched request is handled.
223 * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
224 * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
225 * @param keys Array of keys to assign to regex matches in the request url.
226 */
227 expectGET(
228 url: string | RegExp | ((url: string) => boolean),
229 headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean),
230 keys?: string[],
231 ): mock.IRequestHandler;
232
233 /**
234 * Creates a new request expectation for HEAD requests.
235 * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false.
236 * Returns an object with respond method that controls how a matched request is handled.
237 * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
238 * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
239 * @param keys Array of keys to assign to regex matches in the request url.
240 */
241
242 expectHEAD(
243 url: string | RegExp | ((url: string) => boolean),
244 headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean),
245 keys?: string[],
246 ): mock.IRequestHandler;
247
248 /**
249 * Creates a new request expectation for JSONP requests.
250 * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, or if function returns false.
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 keys Array of keys to assign to regex matches in the request url.
254 */
255 expectJSONP(
256 url: string | RegExp | ((url: string) => boolean),
257 keys?: string[],
258 ): mock.IRequestHandler;
259
260 /**
261 * Creates a new request expectation for PATCH requests.
262 * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false.
263 * Returns an object with respond method that controls how a matched request is handled.
264 * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
265 * @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.
266 * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
267 * @param keys Array of keys to assign to regex matches in the request url.
268 */
269 expectPATCH(
270 url: string | RegExp | ((url: string) => boolean),
271 data?: string | RegExp | object | ((data: string) => boolean),
272 headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean),
273 keys?: string[],
274 ): mock.IRequestHandler;
275
276 /**
277 * Creates a new request expectation for POST requests.
278 * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false.
279 * Returns an object with respond method that controls how a matched request is handled.
280 * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
281 * @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.
282 * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
283 * @param keys Array of keys to assign to regex matches in the request url.
284 */
285 expectPOST(
286 url: string | RegExp | ((url: string) => boolean),
287 data?: string | RegExp | object | ((data: string) => boolean),
288 headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean),
289 keys?: string[],
290 ): mock.IRequestHandler;
291
292 /**
293 * Creates a new request expectation for PUT requests.
294 * Throws a preformatted error if expectation(s) don't match supplied string, regular expression, object, or if function returns false.
295 * Returns an object with respond method that controls how a matched request is handled.
296 * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
297 * @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.
298 * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
299 * @param keys Array of keys to assign to regex matches in the request url.
300 */
301 expectPUT(
302 url: string | RegExp | ((url: string) => boolean),
303 data?: string | RegExp | object | ((data: string) => boolean),
304 headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean),
305 keys?: string[],
306 ): mock.IRequestHandler;
307
308 /**
309 * Creates a new request expectation that compares only with the requested route.
310 * This method offers colon delimited matching of the url path, ignoring the query string.
311 * This allows declarations similar to how application routes are configured with `$routeProvider`.
312 * As this method converts the definition url to regex, declaration order is important.
313 * @param method HTTP method
314 * @param url HTTP url string that supports colon param matching
315 */
316 expectRoute(method: string, url: string): mock.IRequestHandler;
317
318 /**
319 * Creates a new backend definition.
320 * Returns an object with respond method that controls how a matched request is handled.
321 * @param method HTTP method.
322 * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
323 * @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.
324 * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
325 * @param keys Array of keys to assign to regex matches in the request url.
326 */
327 when(
328 method: string,
329 url: string | RegExp | ((url: string) => boolean),
330 data?: string | RegExp | object | ((data: string) => boolean),
331 headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean),
332 keys?: string[],
333 ): mock.IRequestHandler;
334
335 /**
336 * Creates a new backend definition for DELETE requests.
337 * Returns an object with respond method that controls how a matched request is handled.
338 * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
339 * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
340 * @param keys Array of keys to assign to regex matches in the request url.
341 */
342 whenDELETE(
343 url: string | RegExp | ((url: string) => boolean),
344 headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean),
345 keys?: string[],
346 ): mock.IRequestHandler;
347
348 /**
349 * Creates a new backend definition for GET requests.
350 * Returns an object with respond method that controls how a matched request is handled.
351 * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
352 * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
353 * @param keys Array of keys to assign to regex matches in request url described above
354 * @param keys Array of keys to assign to regex matches in the request url.
355 */
356 whenGET(
357 url: string | RegExp | ((url: string) => boolean),
358 headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean),
359 keys?: string[],
360 ): mock.IRequestHandler;
361
362 /**
363 * Creates a new backend definition for HEAD requests.
364 * Returns an object with respond method that controls how a matched request is handled.
365 * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
366 * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
367 * @param keys Array of keys to assign to regex matches in the request url.
368 */
369 whenHEAD(
370 url: string | RegExp | ((url: string) => boolean),
371 headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean),
372 keys?: string[],
373 ): mock.IRequestHandler;
374
375 /**
376 * Creates a new backend definition for JSONP requests.
377 * Returns an object with respond method that controls how a matched request is handled.
378 * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
379 * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
380 * @param keys Array of keys to assign to regex matches in the request url.
381 */
382 whenJSONP(
383 url: string | RegExp | ((url: string) => boolean),
384 keys?: string[],
385 ): mock.IRequestHandler;
386
387 /**
388 * Creates a new backend definition for PATCH requests.
389 * Returns an object with respond method that controls how a matched request is handled.
390 * @param url HTTP url string, regular expression or function that receives a url and returns true if the url matches the current expctation.
391 * @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.
392 * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
393 * @param keys Array of keys to assign to regex matches in the request url.
394 */
395 whenPATCH(
396 url: string | RegExp | ((url: string) => boolean),
397 data?: string | RegExp | object | ((data: string) => boolean),
398 headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean),
399 keys?: string[],
400 ): mock.IRequestHandler;
401
402 /**
403 * Creates a new backend definition for POST requests.
404 * Returns an object with respond method that controls how a matched request is handled.
405 * @param url HTTP url string, regular expression or function that receives a url and returns true
406 * if the url matches the current definition.
407 * @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.
408 * @param headers HTTP headers object or function that receives the headers and returns true if the headers match the current expectation.
409 * @param keys Array of keys to assign to regex matches in the request url.
410 */
411 whenPOST(
412 url: string | RegExp | ((url: string) => boolean),
413 data?: string | RegExp | object | ((data: string) => boolean),
414 headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean),
415 keys?: string[],
416 ): mock.IRequestHandler;
417
418 /**
419 * Creates a new backend definition for PUT requests.
420 * Returns an object with respond method that controls how a matched request is handled.
421 * @param url HTTP url string, regular expression or function that receives a url and returns true
422 * if the url matches the current definition.
423 * @param data HTTP request body or function that receives data string and returns true if the data
424 * is as expected.
425 * @param headers HTTP headers or function that receives http header object and returns true if the
426 * headers match the current definition.
427 * @param keys Array of keys to assign to regex matches in the request url.
428 */
429 whenPUT(
430 url: string | RegExp | ((url: string) => boolean),
431 data?: string | RegExp | object | ((data: string) => boolean),
432 headers?: mock.IHttpHeaders | ((headers: mock.IHttpHeaders) => boolean),
433 keys?: string[],
434 ): mock.IRequestHandler;
435
436 /**
437 * Creates a new backend definition that compares only with the requested route.
438 * This method offers colon delimited matching of the url path, ignoring the query string.
439 * This allows declarations similar to how application routes are configured with `$routeProvider`.
440 * As this method converts the definition url to regex, declaration order is important.
441 * @param method HTTP method.
442 * @param url HTTP url string that supports colon param matching.
443 */
444 whenRoute(method: string, url: string): mock.IRequestHandler;
445 }
446
447 ///////////////////////////////////////////////////////////////////////////
448 // FlushPendingTasksService
449 // see https://docs.angularjs.org/api/ngMock/service/$flushPendingTasks
450 ///////////////////////////////////////////////////////////////////////////
451 interface IFlushPendingTasksService {
452 /**
453 * Flushes all currently pending tasks and executes the corresponding callbacks.
454 *
455 * Optionally, you can also pass a `delay` argument to only flush tasks that are scheduled to be
456 * executed within `delay` milliseconds. Currently, `delay` only applies to timeouts, since all
457 * other tasks have a delay of 0 (i.e. they are scheduled to be executed as soon as possible, but
458 * still asynchronously).
459 *
460 * If no delay is specified, it uses a delay such that all currently pending tasks are flushed.
461 *
462 * The types of tasks that are flushed include:
463 *
464 * - Pending timeouts (via `$timeout`).
465 * - Pending tasks scheduled via `$applyAsync`.
466 * - Pending tasks scheduled via `$evalAsync`.
467 * These include tasks scheduled via `$evalAsync()` indirectly (such as `$q` promises).
468 *
469 * > Periodic tasks scheduled via `$interval` use a different queue and are not flushed by
470 * > `$flushPendingTasks()`. Use `$interval.flush(millis)` instead.
471 *
472 * @param millis - The number of milliseconds to flush.
473 */
474 (delay?: number): void;
475 }
476
477 ///////////////////////////////////////////////////////////////////////////
478 // VerifyNoPendingTasksService
479 // see https://docs.angularjs.org/api/ngMock/service/$verifyNoPendingTasks
480 ///////////////////////////////////////////////////////////////////////////
481 interface IVerifyNoPendingTasksService {
482 /**
483 * Verifies that there are no pending tasks that need to be flushed. It throws an error if there
484 * are still pending tasks.
485 *
486 * You can check for a specific type of tasks only, by specifying a `taskType`.
487 *
488 * Available task types:
489 *
490 * - `$timeout`: Pending timeouts (via `$timeout`).
491 * - `$http`: Pending HTTP requests (via `$http`).
492 * - `$route`: In-progress route transitions (via `$route`).
493 * - `$applyAsync`: Pending tasks scheduled via `$applyAsync`.
494 * - `$evalAsync`: Pending tasks scheduled via `$evalAsync`.
495 * These include tasks scheduled via `$evalAsync()` indirectly (such as `$q` promises).
496 *
497 * > Periodic tasks scheduled via `$interval` use a different queue and are not taken into
498 * > account by `$verifyNoPendingTasks()`. There is currently no way to verify that there are no
499 * > pending `$interval` tasks.
500 *
501 * @param taskType - The type of tasks to check for.
502 */
503 (taskType?: string): void;
504 }
505
506 ///////////////////////////////////////////////////////////////////////////
507 // AnimateService
508 // see https://docs.angularjs.org/api/ngMock/service/$animate
509 ///////////////////////////////////////////////////////////////////////////
510 namespace animate {
511 interface IAnimateService {
512 /**
513 * This method will close all pending animations (both Javascript and CSS) and it will also flush any remaining
514 * animation frames and/or callbacks.
515 */
516 closeAndFlush(): void;
517
518 /**
519 * This method is used to flush the pending callbacks and animation frames to either start
520 * an animation or conclude an animation. Note that this will not actually close an
521 * actively running animation (see `closeAndFlush()`} for that).
522 */
523 flush(): void;
524 }
525 }
526
527 namespace mock {
528 /** Object returned by the the mocked HttpBackendService expect/when methods */
529 interface IRequestHandler {
530 /**
531 * Controls the response for a matched request using a function to construct the response.
532 * Returns the RequestHandler object for possible overrides.
533 * @param func Function that receives the request HTTP method, url, data, headers, and an array of keys
534 * to regex matches in the request url and returns an array containing response status (number), data,
535 * headers, and status text.
536 */
537 respond(
538 func: (
539 method: string,
540 url: string,
541 data: string | object,
542 headers: IHttpHeaders,
543 params: { [key: string]: string },
544 ) => [number, string | object, IHttpHeaders, string],
545 ): IRequestHandler;
546
547 /**
548 * Controls the response for a matched request using supplied static data to construct the response.
549 * Returns the RequestHandler object for possible overrides.
550 * @param status HTTP status code to add to the response.
551 * @param data Data to add to the response.
552 * @param headers Headers object to add to the response.
553 * @param responseText Response text to add to the response.
554 */
555 respond(
556 status: number,
557 data?: string | object,
558 headers?: IHttpHeaders,
559 responseText?: string,
560 ): IRequestHandler;
561
562 /**
563 * Controls the response for a matched request using the HTTP status code 200 and supplied static data to construct the response.
564 * Returns the RequestHandler object for possible overrides.
565 * @param data Data to add to the response.
566 * @param headers Headers object to add to the response.
567 * @param responseText Response text to add to the response.
568 */
569 respond(
570 data: string | object,
571 headers?: IHttpHeaders,
572 responseText?: string,
573 ): IRequestHandler;
574
575 /**
576 * Any request matching a backend definition or expectation with passThrough handler will be
577 * passed through to the real backend (an XHR request will be made to the server.)
578 * Available when ngMockE2E is loaded
579 */
580 passThrough(): IRequestHandler;
581 }
582
583 interface IHttpHeaders {
584 [headerName: string]: any;
585 }
586
587 /**
588 * Contains additional event data used by the `browserTrigger` function when creating an event.
589 */
590 interface IBrowserTriggerEventData {
591 /**
592 * [Event.bubbles](https://developer.mozilla.org/docs/Web/API/Event/bubbles).
593 * Not applicable to all events.
594 */
595 bubbles?: boolean | undefined;
596 /**
597 * [Event.cancelable](https://developer.mozilla.org/docs/Web/API/Event/cancelable).
598 * Not applicable to all events.
599 */
600 cancelable?: boolean | undefined;
601 /**
602 * [charCode](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/charcode)
603 * for keyboard events (keydown, keypress, and keyup).
604 */
605 charcode?: number | undefined;
606 /**
607 * [data](https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent/data) for
608 * [CompositionEvents](https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent).
609 */
610 data?: string | undefined;
611 /**
612 * The elapsedTime for
613 * [TransitionEvent](https://developer.mozilla.org/docs/Web/API/TransitionEvent)
614 * and [AnimationEvent](https://developer.mozilla.org/docs/Web/API/AnimationEvent).
615 */
616 elapsedTime?: number | undefined;
617 /**
618 * [keyCode](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/keycode)
619 * for keyboard events (keydown, keypress, and keyup).
620 */
621 keycode?: number | undefined;
622 /**
623 * An array of possible modifier keys (ctrl, alt, shift, meta) for
624 * [MouseEvent](https://developer.mozilla.org/docs/Web/API/MouseEvent) and
625 * keyboard events (keydown, keypress, and keyup).
626 */
627 keys?: Array<"ctrl" | "alt" | "shift" | "meta"> | undefined;
628 /**
629 * The [relatedTarget](https://developer.mozilla.org/docs/Web/API/MouseEvent/relatedTarget)
630 * for [MouseEvent](https://developer.mozilla.org/docs/Web/API/MouseEvent).
631 */
632 relatedTarget?: Node | undefined;
633 /**
634 * [which](https://developer.mozilla.org/docs/Web/API/KeyboardEvent/which)
635 * for keyboard events (keydown, keypress, and keyup).
636 */
637 which?: number | undefined;
638 /**
639 * x-coordinates for [MouseEvent](https://developer.mozilla.org/docs/Web/API/MouseEvent)
640 * and [TouchEvent](https://developer.mozilla.org/docs/Web/API/TouchEvent).
641 */
642 x?: number | undefined;
643 /**
644 * y-coordinates for [MouseEvent](https://developer.mozilla.org/docs/Web/API/MouseEvent)
645 * and [TouchEvent](https://developer.mozilla.org/docs/Web/API/TouchEvent).
646 */
647 y?: number | undefined;
648 }
649 }
650}
651
652///////////////////////////////////////////////////////////////////////////////
653// functions attached to global object (window)
654///////////////////////////////////////////////////////////////////////////////
655// Use `angular.mock.module` instead of `module`, as `module` conflicts with commonjs.
656// declare var module: (...modules: any[]) => any;
657declare global {
658 const inject: angular.IInjectStatic;
659
660 /**
661 * This is a global (window) function that is only available when the `ngMock` module is included.
662 * It can be used to trigger a native browser event on an element, which is useful for unit testing.
663 *
664 * @param element Either a wrapped jQuery/jqLite node or a DOM element.
665 * @param eventType Optional event type. If none is specified, the function tries to determine the
666 * right event type for the element, e.g. `change` for `input[text]`.
667 * @param eventData An optional object which contains additional event data used when creating the
668 * event.
669 */
670 function browserTrigger(
671 element: JQuery | Element,
672 eventType?: string,
673 eventData?: angular.mock.IBrowserTriggerEventData,
674 ): void;
675}
676
\No newline at end of file