mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Update types and docs for angular-route and angular-mocks (#27473)
* angular-route: Update types and docs for `IRoute` * angular-mocks: Update types and docs for 1.7 Related to angular/angular.js#16603 and angular/angular.js#16640.
This commit is contained in:
parent
21077b2657
commit
b7d70d6879
@ -87,7 +87,6 @@ timeoutService.verifyNoPendingTasks();
|
||||
let intervalService: ng.IIntervalService;
|
||||
let intervalServiceTimeActuallyAdvanced: number;
|
||||
|
||||
intervalServiceTimeActuallyAdvanced = intervalService.flush();
|
||||
intervalServiceTimeActuallyAdvanced = intervalService.flush(1234);
|
||||
|
||||
///////////////////////////////////////
|
||||
@ -1516,6 +1515,23 @@ requestHandler.respond(404, { key: 'value' });
|
||||
requestHandler.respond(404, { key: 'value' }, { header: 'value' });
|
||||
requestHandler.respond(404, { key: 'value' }, { header: 'value' }, 'responseText');
|
||||
|
||||
///////////////////////////////////////
|
||||
// IFlushPendingTasksService
|
||||
///////////////////////////////////////
|
||||
let $flushPendingTasks: ng.IFlushPendingTasksService;
|
||||
$flushPendingTasks();
|
||||
$flushPendingTasks(42);
|
||||
|
||||
///////////////////////////////////////
|
||||
// IVerifyNoPendingTasksService
|
||||
///////////////////////////////////////
|
||||
let $verifyNoPendingTasks: ng.IVerifyNoPendingTasksService;
|
||||
$verifyNoPendingTasks();
|
||||
$verifyNoPendingTasks('task type');
|
||||
|
||||
///////////////////////////////////////
|
||||
// browserTrigger
|
||||
///////////////////////////////////////
|
||||
browserTrigger(document.body, 'click');
|
||||
browserTrigger(angular.element(document.body), 'click');
|
||||
browserTrigger(angular.element(document.body), 'click', { which: 1, keys: ['ctrl'] });
|
||||
|
||||
114
types/angular-mocks/index.d.ts
vendored
114
types/angular-mocks/index.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
// Type definitions for Angular JS (ngMock, ngMockE2E module) 1.6
|
||||
// Type definitions for Angular JS (ngMock, ngMockE2E module) 1.7
|
||||
// Project: http://angularjs.org
|
||||
// Definitions by: Diego Vilar <https://github.com/diegovilar>
|
||||
// Tony Curtis <https://github.com/daltin>
|
||||
@ -61,7 +61,38 @@ declare module 'angular' {
|
||||
// Augments the original service
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
interface ITimeoutService {
|
||||
/**
|
||||
* **Deprecated** since version 1.7.3. (Use `$flushPendingTasks` instead.)
|
||||
*
|
||||
* ---
|
||||
* Flushes the queue of pending tasks.
|
||||
*
|
||||
* _This method is essentially an alias of `$flushPendingTasks`._
|
||||
*
|
||||
* > For historical reasons, this method will also flush non-`$timeout` pending tasks, such as
|
||||
* > `$q` promises and tasks scheduled via `$applyAsync` and `$evalAsync`.
|
||||
*
|
||||
* @param delay - The maximum timeout amount to flush up until.
|
||||
*/
|
||||
flush(delay?: number): void;
|
||||
|
||||
/**
|
||||
* **Deprecated** since version 1.7.3. (Use `$verifyNoPendingTasks` instead.)
|
||||
*
|
||||
* ---
|
||||
* Verifies that there are no pending tasks that need to be flushed. It throws an error if there
|
||||
* are still pending tasks.
|
||||
*
|
||||
* _This method is essentially an alias of `$verifyNoPendingTasks` (called with no arguments)._
|
||||
*
|
||||
* > For historical reasons, this method will also verify non-`$timeout` pending tasks, such as
|
||||
* > pending `$http` requests, in-progress `$route` transitions, unresolved `$q` promises and
|
||||
* > tasks scheduled via `$applyAsync` and `$evalAsync`.
|
||||
* >
|
||||
* > It is recommended to use `$verifyNoPendingTasks` instead, which additionally supports
|
||||
* > verifying a specific type of tasks. For example, you can verify there are no pending
|
||||
* > timeouts with `$verifyNoPendingTasks('$timeout')`.
|
||||
*/
|
||||
verifyNoPendingTasks(): void;
|
||||
}
|
||||
|
||||
@ -71,7 +102,13 @@ declare module 'angular' {
|
||||
// Augments the original service
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
interface IIntervalService {
|
||||
flush(millis?: number): number;
|
||||
/**
|
||||
* Runs interval tasks scheduled to be run in the next `millis` milliseconds.
|
||||
*
|
||||
* @param millis - The maximum timeout amount to flush up until.
|
||||
* @return The amount of time moved forward.
|
||||
*/
|
||||
flush(millis: number): number;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
@ -415,6 +452,65 @@ declare module 'angular' {
|
||||
whenRoute(method: string, url: string): mock.IRequestHandler;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// FlushPendingTasksService
|
||||
// see https://docs.angularjs.org/api/ngMock/service/$flushPendingTasks
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
interface IFlushPendingTasksService {
|
||||
/**
|
||||
* Flushes all currently pending tasks and executes the corresponding callbacks.
|
||||
*
|
||||
* Optionally, you can also pass a `delay` argument to only flush tasks that are scheduled to be
|
||||
* executed within `delay` milliseconds. Currently, `delay` only applies to timeouts, since all
|
||||
* other tasks have a delay of 0 (i.e. they are scheduled to be executed as soon as possible, but
|
||||
* still asynchronously).
|
||||
*
|
||||
* If no delay is specified, it uses a delay such that all currently pending tasks are flushed.
|
||||
*
|
||||
* The types of tasks that are flushed include:
|
||||
*
|
||||
* - Pending timeouts (via `$timeout`).
|
||||
* - Pending tasks scheduled via `$applyAsync`.
|
||||
* - Pending tasks scheduled via `$evalAsync`.
|
||||
* These include tasks scheduled via `$evalAsync()` indirectly (such as `$q` promises).
|
||||
*
|
||||
* > Periodic tasks scheduled via `$interval` use a different queue and are not flushed by
|
||||
* > `$flushPendingTasks()`. Use `$interval.flush(millis)` instead.
|
||||
*
|
||||
* @param millis - The number of milliseconds to flush.
|
||||
*/
|
||||
(delay?: number): void;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// VerifyNoPendingTasksService
|
||||
// see https://docs.angularjs.org/api/ngMock/service/$verifyNoPendingTasks
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
interface IVerifyNoPendingTasksService {
|
||||
/**
|
||||
* Verifies that there are no pending tasks that need to be flushed. It throws an error if there
|
||||
* are still pending tasks.
|
||||
*
|
||||
* You can check for a specific type of tasks only, by specifying a `taskType`.
|
||||
*
|
||||
* Available task types:
|
||||
*
|
||||
* - `$timeout`: Pending timeouts (via `$timeout`).
|
||||
* - `$http`: Pending HTTP requests (via `$http`).
|
||||
* - `$route`: In-progress route transitions (via `$route`).
|
||||
* - `$applyAsync`: Pending tasks scheduled via `$applyAsync`.
|
||||
* - `$evalAsync`: Pending tasks scheduled via `$evalAsync`.
|
||||
* These include tasks scheduled via `$evalAsync()` indirectly (such as `$q` promises).
|
||||
*
|
||||
* > Periodic tasks scheduled via `$interval` use a different queue and are not taken into
|
||||
* > account by `$verifyNoPendingTasks()`. There is currently no way to verify that there are no
|
||||
* > pending `$interval` tasks.
|
||||
*
|
||||
* @param taskType - The type of tasks to check for.
|
||||
*/
|
||||
(taskType?: string): void;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// AnimateService
|
||||
// see https://docs.angularjs.org/api/ngMock/service/$animate
|
||||
@ -515,6 +611,11 @@ declare module 'angular' {
|
||||
* for keyboard events (keydown, keypress, and keyup).
|
||||
*/
|
||||
charcode?: number;
|
||||
/**
|
||||
* [data](https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent/data) for
|
||||
* [CompositionEvents](https://developer.mozilla.org/en-US/docs/Web/API/CompositionEvent).
|
||||
*/
|
||||
data?: string;
|
||||
/**
|
||||
* The elapsedTime for
|
||||
* [TransitionEvent](https://developer.mozilla.org/docs/Web/API/TransitionEvent)
|
||||
@ -568,10 +669,11 @@ declare global {
|
||||
* This is a global (window) function that is only available when the `ngMock` module is included.
|
||||
* It can be used to trigger a native browser event on an element, which is useful for unit testing.
|
||||
*
|
||||
* @param element Either a wrapped jQuery/jqLite node or a DOM element
|
||||
* @param eventType Optional event type. If none is specified, the function tries to determine
|
||||
* the right event type for the element, e.g. `change` for `input[text]`.
|
||||
* @param eventData An optional object which contains additional event data used when creating the event.
|
||||
* @param element Either a wrapped jQuery/jqLite node or a DOM element.
|
||||
* @param eventType Optional event type. If none is specified, the function tries to determine the
|
||||
* right event type for the element, e.g. `change` for `input[text]`.
|
||||
* @param eventData An optional object which contains additional event data used when creating the
|
||||
* event.
|
||||
*/
|
||||
function browserTrigger(
|
||||
element: JQuery | Element,
|
||||
|
||||
@ -39,6 +39,21 @@ $routeProvider
|
||||
return "I return a string"
|
||||
}
|
||||
})
|
||||
.when('/projects/:projectId/dashboard6', {
|
||||
resolve: {
|
||||
foo: () => 'foo',
|
||||
bar: () => 'bar',
|
||||
},
|
||||
resolveAs: 'baz',
|
||||
resolveRedirectTo: [
|
||||
'$http',
|
||||
($http: ng.IHttpService) => $http.get('/is-admin').then(() => '/admin/lounge', () => undefined),
|
||||
],
|
||||
})
|
||||
.when('/projects/:projectId/dashboard7', {
|
||||
reloadOnUrl: false,
|
||||
resolveRedirectTo: () => (Math.random() < 0.5) ? '/some/route' : undefined,
|
||||
})
|
||||
.otherwise({ redirectTo: '/' })
|
||||
.otherwise({ redirectTo: ($routeParams?: ng.route.IRouteParamsService, $locationPath?: string, $locationSearch?: any) => "" })
|
||||
.otherwise("/");
|
||||
|
||||
121
types/angular-route/index.d.ts
vendored
121
types/angular-route/index.d.ts
vendored
@ -1,6 +1,7 @@
|
||||
// Type definitions for Angular JS (ngRoute module) 1.3
|
||||
// Type definitions for Angular JS (ngRoute module) 1.7
|
||||
// Project: http://angularjs.org
|
||||
// Definitions by: Jonathan Park <https://github.com/park9140>
|
||||
// George Kalpakas <https://github.com/gkalpak>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
@ -52,7 +53,7 @@ declare module 'angular' {
|
||||
*/
|
||||
interface IRoute {
|
||||
/**
|
||||
* {(string|function()=}
|
||||
* {(string|Function)=}
|
||||
* Controller fn that should be associated with newly created scope or the name of a registered controller if passed as a string.
|
||||
*/
|
||||
controller?: string | InlineAnnotatedFunction;
|
||||
@ -61,56 +62,122 @@ declare module 'angular' {
|
||||
*/
|
||||
controllerAs?: string;
|
||||
/**
|
||||
* Undocumented?
|
||||
*/
|
||||
name?: string;
|
||||
/**
|
||||
* {string=|function()=}
|
||||
* {(string|Function)=}
|
||||
* Html template as a string or a function that returns an html template as a string which should be used by ngView or ngInclude directives. This property takes precedence over templateUrl.
|
||||
*
|
||||
* If template is a function, it will be called with the following parameters:
|
||||
*
|
||||
* {Array.<Object>} - route parameters extracted from the current $location.path() by applying the current route
|
||||
*/
|
||||
template?: string | { ($routeParams?: angular.route.IRouteParamsService): string; }
|
||||
template?: string | { ($routeParams?: IRouteParamsService): string; }
|
||||
/**
|
||||
* {string=|function()=}
|
||||
* {(string|Function)=}
|
||||
* Path or function that returns a path to an html template that should be used by ngView.
|
||||
*
|
||||
* If templateUrl is a function, it will be called with the following parameters:
|
||||
*
|
||||
* {Array.<Object>} - route parameters extracted from the current $location.path() by applying the current route
|
||||
*/
|
||||
templateUrl?: string | { ($routeParams?: angular.route.IRouteParamsService): string; }
|
||||
templateUrl?: string | { ($routeParams?: IRouteParamsService): string; }
|
||||
/**
|
||||
* {Object.<string, function>=} - An optional map of dependencies which should be injected into the controller. If any of these dependencies are promises, the router will wait for them all to be resolved or one to be rejected before the controller is instantiated. If all the promises are resolved successfully, the values of the resolved promises are injected and $routeChangeSuccess event is fired. If any of the promises are rejected the $routeChangeError event is fired. The map object is:
|
||||
* {Object.<string, Function>=}
|
||||
* An optional map of dependencies which should be injected into the controller. If any of these
|
||||
* dependencies are promises, the router will wait for them all to be resolved or one to be rejected before
|
||||
* the controller is instantiated.
|
||||
* If all the promises are resolved successfully, the values of the resolved promises are injected and
|
||||
* `$routeChangeSuccess` event is fired. If any of the promises are rejected the `$routeChangeError` event
|
||||
* is fired.
|
||||
* For easier access to the resolved dependencies from the template, the `resolve` map will be available on
|
||||
* the scope of the route, under `$resolve` (by default) or a custom name specified by the `resolveAs`
|
||||
* property (see below). This can be particularly useful, when working with components as route templates.
|
||||
*
|
||||
* - key - {string}: a name of a dependency to be injected into the controller.
|
||||
* - factory - {string|function}: If string then it is an alias for a service. Otherwise if function, then it is injected and the return value is treated as the dependency. If the result is a promise, it is resolved before its value is injected into the controller. Be aware that ngRoute.$routeParams will still refer to the previous route within these resolve functions. Use $route.current.params to access the new route parameters, instead.
|
||||
* > **Note:** If your scope already contains a property with this name, it will be hidden or overwritten.
|
||||
* > Make sure, you specify an appropriate name for this property, that does not collide with other
|
||||
* > properties on the scope.
|
||||
*
|
||||
* The map object is:
|
||||
*
|
||||
* - `key` – `{string}`: a name of a dependency to be injected into the controller.
|
||||
* - `factory` - `{string|Function}`: If `string` then it is an alias for a service. Otherwise if function,
|
||||
* then it is called with `$injector#invoke()` and the return value is treated as the dependency. If the
|
||||
* result is a promise, it is resolved before its value is injected into the controller. Be aware that
|
||||
* `ngRoute.$routeParams` will still refer to the previous route within these resolve functions. Use
|
||||
* `$route.current.params` to access the new route parameters, instead.
|
||||
*/
|
||||
resolve?: { [key: string]: any };
|
||||
/**
|
||||
* {(string|function())=}
|
||||
* Value to update $location path with and trigger route redirection.
|
||||
*
|
||||
* If redirectTo is a function, it will be called with the following parameters:
|
||||
*
|
||||
* - {Object.<string>} - route parameters extracted from the current $location.path() by applying the current route templateUrl.
|
||||
* - {string} - current $location.path()
|
||||
* - {Object} - current $location.search()
|
||||
* - The custom redirectTo function is expected to return a string which will be used to update $location.path() and $location.search().
|
||||
* {string=}
|
||||
* The name under which the `resolve` map will be available on the scope of the route. If omitted, defaults
|
||||
* to `$resolve`.
|
||||
*/
|
||||
redirectTo?: string | { ($routeParams?: angular.route.IRouteParamsService, $locationPath?: string, $locationSearch?: any): string };
|
||||
resolveAs?: string;
|
||||
/**
|
||||
* Reload route when only $location.search() or $location.hash() changes.
|
||||
* {(string|Function)=}
|
||||
* Value to update `$location` path with and trigger route redirection.
|
||||
*
|
||||
* This option defaults to true. If the option is set to false and url in the browser changes, then $routeUpdate event is broadcasted on the root scope.
|
||||
* If `redirectTo` is a function, it will be called with the following parameters:
|
||||
*
|
||||
* - `{Object.<string>}` - route parameters extracted from the current `$location.path()` by applying the
|
||||
* current route templateUrl.
|
||||
* - `{string}` - current `$location.path()`
|
||||
* - `{Object}` - current `$location.search()`
|
||||
*
|
||||
* The custom `redirectTo` function is expected to return a string which will be used to update
|
||||
* `$location.url()`. If the function throws an error, no further processing will take place and the
|
||||
* `$routeChangeError` event will be fired.
|
||||
*
|
||||
* Routes that specify `redirectTo` will not have their controllers, template functions or resolves called,
|
||||
* the `$location` will be changed to the redirect url and route processing will stop. The exception to this
|
||||
* is if the `redirectTo` is a function that returns `undefined`. In this case the route transition occurs
|
||||
* as though there was no redirection.
|
||||
*/
|
||||
redirectTo?: string | { ($routeParams?: IRouteParamsService, $locationPath?: string, $locationSearch?: any): string };
|
||||
/**
|
||||
* {Function=}
|
||||
* A function that will (eventually) return the value to update `$location` URL with and trigger route
|
||||
* redirection. In contrast to `redirectTo`, dependencies can be injected into `resolveRedirectTo` and the
|
||||
* return value can be either a string or a promise that will be resolved to a string.
|
||||
*
|
||||
* Similar to `redirectTo`, if the return value is `undefined` (or a promise that gets resolved to
|
||||
* `undefined`), no redirection takes place and the route transition occurs as though there was no
|
||||
* redirection.
|
||||
*
|
||||
* If the function throws an error or the returned promise gets rejected, no further processing will take
|
||||
* place and the `$routeChangeError` event will be fired.
|
||||
*
|
||||
* `redirectTo` takes precedence over `resolveRedirectTo`, so specifying both on the same route definition,
|
||||
* will cause the latter to be ignored.
|
||||
*/
|
||||
resolveRedirectTo?: angular.Injectable<(...deps: any[]) => angular.IPromise<string | undefined> | string | undefined>;
|
||||
/**
|
||||
* {boolean=true}
|
||||
* Reload route when any part of the URL changes (including the path) even if the new URL maps to the same
|
||||
* route.
|
||||
*
|
||||
* If the option is set to `false` and the URL in the browser changes, but the new URL maps to the same
|
||||
* route, then a `$routeUpdate` event is broadcasted on the root scope (without reloading the route).
|
||||
*
|
||||
* Defaults to `true`.
|
||||
*/
|
||||
reloadOnUrl?: boolean;
|
||||
/**
|
||||
* {boolean=true}
|
||||
* Reload route when only `$location.search()` or `$location.hash()` changes.
|
||||
*
|
||||
* If the option is set to `false` and the URL in the browser changes, then a `$routeUpdate` event is
|
||||
* broadcasted on the root scope (without reloading the route).
|
||||
*
|
||||
* > Note: This option has no effect if `reloadOnUrl` is set to `false`.
|
||||
*
|
||||
* Defaults to `true`.
|
||||
*/
|
||||
reloadOnSearch?: boolean;
|
||||
/**
|
||||
* Match routes without being case sensitive
|
||||
* {boolean=false}
|
||||
* Match routes without being case sensitive.
|
||||
* If the option is set to `true`, then the particular route can be matched without being case sensitive.
|
||||
*
|
||||
* This option defaults to false. If the option is set to true, then the particular route can be matched without being case sensitive
|
||||
* Defaults to `false`.
|
||||
*/
|
||||
caseInsensitiveMatch?: boolean;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user