UNPKG

5.61 kBTypeScriptView Raw
1/**
2 * @license Angular v15.1.2
3 * (c) 2010-2022 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7
8import { Type } from '@angular/core';
9
10
11/**
12 * A helper function to use when unit testing AngularJS services that depend upon downgraded Angular
13 * services.
14 *
15 * This function returns an AngularJS module that is configured to wire up the AngularJS and Angular
16 * injectors without the need to actually bootstrap a hybrid application.
17 * This makes it simpler and faster to unit test services.
18 *
19 * Use the returned AngularJS module in a call to
20 * [`angular.mocks.module`](https://docs.angularjs.org/api/ngMock/function/angular.mock.module) to
21 * include this module in the unit test injector.
22 *
23 * In the following code snippet, we are configuring the `$injector` with two modules:
24 * The AngularJS `ng1AppModule`, which is the AngularJS part of our hybrid application and the
25 * `Ng2AppModule`, which is the Angular part.
26 *
27 * <code-example path="upgrade/static/ts/full/module.spec.ts"
28 * region="angularjs-setup"></code-example>
29 *
30 * Once this is done we can get hold of services via the AngularJS `$injector` as normal.
31 * Services that are (or have dependencies on) a downgraded Angular service, will be instantiated as
32 * needed by the Angular root `Injector`.
33 *
34 * In the following code snippet, `heroesService` is a downgraded Angular service that we are
35 * accessing from AngularJS.
36 *
37 * <code-example path="upgrade/static/ts/full/module.spec.ts"
38 * region="angularjs-spec"></code-example>
39 *
40 * <div class="alert is-important">
41 *
42 * This helper is for testing services not components.
43 * For Component testing you must still bootstrap a hybrid app. See `UpgradeModule` or
44 * `downgradeModule` for more information.
45 *
46 * </div>
47 *
48 * <div class="alert is-important">
49 *
50 * The resulting configuration does not wire up AngularJS digests to Zone hooks. It is the
51 * responsibility of the test writer to call `$rootScope.$apply`, as necessary, to trigger
52 * AngularJS handlers of async events from Angular.
53 *
54 * </div>
55 *
56 * <div class="alert is-important">
57 *
58 * The helper sets up global variables to hold the shared Angular and AngularJS injectors.
59 *
60 * * Only call this helper once per spec.
61 * * Do not use `createAngularJSTestingModule` in the same spec as `createAngularTestingModule`.
62 *
63 * </div>
64 *
65 * Here is the example application and its unit tests that use `createAngularTestingModule`
66 * and `createAngularJSTestingModule`.
67 *
68 * <code-tabs>
69 * <code-pane header="module.spec.ts" path="upgrade/static/ts/full/module.spec.ts"></code-pane>
70 * <code-pane header="module.ts" path="upgrade/static/ts/full/module.ts"></code-pane>
71 * </code-tabs>
72 *
73 *
74 * @param angularModules a collection of Angular modules to include in the configuration.
75 *
76 * @publicApi
77 */
78export declare function createAngularJSTestingModule(angularModules: any[]): string;
79
80/**
81 * A helper function to use when unit testing Angular services that depend upon upgraded AngularJS
82 * services.
83 *
84 * This function returns an `NgModule` decorated class that is configured to wire up the Angular
85 * and AngularJS injectors without the need to actually bootstrap a hybrid application.
86 * This makes it simpler and faster to unit test services.
87 *
88 * Use the returned class as an "import" when configuring the `TestBed`.
89 *
90 * In the following code snippet, we are configuring the TestBed with two imports.
91 * The `Ng2AppModule` is the Angular part of our hybrid application and the `ng1AppModule` is the
92 * AngularJS part.
93 *
94 * <code-example path="upgrade/static/ts/full/module.spec.ts" region="angular-setup"></code-example>
95 *
96 * Once this is done we can get hold of services via the Angular `Injector` as normal.
97 * Services that are (or have dependencies on) an upgraded AngularJS service, will be instantiated
98 * as needed by the AngularJS `$injector`.
99 *
100 * In the following code snippet, `HeroesService` is an Angular service that depends upon an
101 * AngularJS service, `titleCase`.
102 *
103 * <code-example path="upgrade/static/ts/full/module.spec.ts" region="angular-spec"></code-example>
104 *
105 * <div class="alert is-important">
106 *
107 * This helper is for testing services not Components.
108 * For Component testing you must still bootstrap a hybrid app. See `UpgradeModule` or
109 * `downgradeModule` for more information.
110 *
111 * </div>
112 *
113 * <div class="alert is-important">
114 *
115 * The resulting configuration does not wire up AngularJS digests to Zone hooks. It is the
116 * responsibility of the test writer to call `$rootScope.$apply`, as necessary, to trigger
117 * AngularJS handlers of async events from Angular.
118 *
119 * </div>
120 *
121 * <div class="alert is-important">
122 *
123 * The helper sets up global variables to hold the shared Angular and AngularJS injectors.
124 *
125 * * Only call this helper once per spec.
126 * * Do not use `createAngularTestingModule` in the same spec as `createAngularJSTestingModule`.
127 *
128 * </div>
129 *
130 * Here is the example application and its unit tests that use `createAngularTestingModule`
131 * and `createAngularJSTestingModule`.
132 *
133 * <code-tabs>
134 * <code-pane header="module.spec.ts" path="upgrade/static/ts/full/module.spec.ts"></code-pane>
135 * <code-pane header="module.ts" path="upgrade/static/ts/full/module.ts"></code-pane>
136 * </code-tabs>
137 *
138 *
139 * @param angularJSModules a collection of the names of AngularJS modules to include in the
140 * configuration.
141 * @param [strictDi] whether the AngularJS injector should have `strictDI` enabled.
142 *
143 * @publicApi
144 */
145export declare function createAngularTestingModule(angularJSModules: string[], strictDi?: boolean): Type<any>;
146
147export { }