UNPKG

13 kBJavaScriptView Raw
1/**
2 * @license Angular v10.0.7
3 * (c) 2010-2020 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7(function (global, factory) {
8 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/core/testing')) :
9 typeof define === 'function' && define.amd ? define('@angular/upgrade/static/testing', ['exports', '@angular/core', '@angular/core/testing'], factory) :
10 (global = global || self, factory((global.ng = global.ng || {}, global.ng.upgrade = global.ng.upgrade || {}, global.ng.upgrade.static = global.ng.upgrade.static || {}, global.ng.upgrade.static.testing = {}), global.ng.core, global.ng.core.testing));
11}(this, (function (exports, core, testing) { 'use strict';
12
13 /**
14 * @license
15 * Copyright Google LLC All Rights Reserved.
16 *
17 * Use of this source code is governed by an MIT-style license that can be
18 * found in the LICENSE file at https://angular.io/license
19 */
20 function noNg() {
21 throw new Error('AngularJS v1.x is not loaded!');
22 }
23 var noNgElement = (function () { return noNg(); });
24 noNgElement.cleanData = noNg;
25 var angular = {
26 bootstrap: noNg,
27 module: noNg,
28 element: noNgElement,
29 injector: noNg,
30 version: undefined,
31 resumeBootstrap: noNg,
32 getTestability: noNg
33 };
34 try {
35 if (window.hasOwnProperty('angular')) {
36 angular = window.angular;
37 }
38 }
39 catch (_a) {
40 // ignore in CJS mode.
41 }
42 /**
43 * @deprecated Use `setAngularJSGlobal` instead.
44 *
45 * @publicApi
46 */
47 function setAngularLib(ng) {
48 setAngularJSGlobal(ng);
49 }
50 /**
51 * @deprecated Use `getAngularJSGlobal` instead.
52 *
53 * @publicApi
54 */
55 function getAngularLib() {
56 return getAngularJSGlobal();
57 }
58 /**
59 * Resets the AngularJS global.
60 *
61 * Used when AngularJS is loaded lazily, and not available on `window`.
62 *
63 * @publicApi
64 */
65 function setAngularJSGlobal(ng) {
66 angular = ng;
67 }
68 /**
69 * Returns the current AngularJS global.
70 *
71 * @publicApi
72 */
73 function getAngularJSGlobal() {
74 return angular;
75 }
76 var bootstrap = function (e, modules, config) { return angular.bootstrap(e, modules, config); };
77 // Do not declare as `module` to avoid webpack bug
78 // (see https://github.com/angular/angular/issues/30050).
79 var module_ = function (prefix, dependencies) { return angular.module(prefix, dependencies); };
80 var element = (function (e) { return angular.element(e); });
81 element.cleanData = function (nodes) { return angular.element.cleanData(nodes); };
82 var injector = function (modules, strictDi) { return angular.injector(modules, strictDi); };
83 var resumeBootstrap = function () { return angular.resumeBootstrap(); };
84 var getTestability = function (e) { return angular.getTestability(e); };
85
86 /**
87 * @license
88 * Copyright Google LLC All Rights Reserved.
89 *
90 * Use of this source code is governed by an MIT-style license that can be
91 * found in the LICENSE file at https://angular.io/license
92 */
93 var $COMPILE = '$compile';
94 var $CONTROLLER = '$controller';
95 var $DELEGATE = '$delegate';
96 var $EXCEPTION_HANDLER = '$exceptionHandler';
97 var $HTTP_BACKEND = '$httpBackend';
98 var $INJECTOR = '$injector';
99 var $INTERVAL = '$interval';
100 var $PARSE = '$parse';
101 var $PROVIDE = '$provide';
102 var $ROOT_SCOPE = '$rootScope';
103 var $SCOPE = '$scope';
104 var $TEMPLATE_CACHE = '$templateCache';
105 var $TEMPLATE_REQUEST = '$templateRequest';
106 var $$TESTABILITY = '$$testability';
107 var COMPILER_KEY = '$$angularCompiler';
108 var DOWNGRADED_MODULE_COUNT_KEY = '$$angularDowngradedModuleCount';
109 var GROUP_PROJECTABLE_NODES_KEY = '$$angularGroupProjectableNodes';
110 var INJECTOR_KEY = '$$angularInjector';
111 var LAZY_MODULE_REF = '$$angularLazyModuleRef';
112 var NG_ZONE_KEY = '$$angularNgZone';
113 var UPGRADE_APP_TYPE_KEY = '$$angularUpgradeAppType';
114 var REQUIRE_INJECTOR = '?^^' + INJECTOR_KEY;
115 var REQUIRE_NG_MODEL = '?ngModel';
116 var UPGRADE_MODULE_NAME = '$$UpgradeModule';
117
118 /**
119 * @license
120 * Copyright Google LLC All Rights Reserved.
121 *
122 * Use of this source code is governed by an MIT-style license that can be
123 * found in the LICENSE file at https://angular.io/license
124 */
125 var $injector = null;
126 var injector$1;
127 function $injectorFactory() {
128 return $injector;
129 }
130 var AngularTestingModule = /** @class */ (function () {
131 function AngularTestingModule(i) {
132 injector$1 = i;
133 }
134 return AngularTestingModule;
135 }());
136 AngularTestingModule.decorators = [
137 { type: core.NgModule, args: [{ providers: [{ provide: $INJECTOR, useFactory: $injectorFactory }] },] }
138 ];
139 AngularTestingModule.ctorParameters = function () { return [
140 { type: core.Injector }
141 ]; };
142 /**
143 * A helper function to use when unit testing Angular services that depend upon upgraded AngularJS
144 * services.
145 *
146 * This function returns an `NgModule` decorated class that is configured to wire up the Angular
147 * and AngularJS injectors without the need to actually bootstrap a hybrid application.
148 * This makes it simpler and faster to unit test services.
149 *
150 * Use the returned class as an "import" when configuring the `TestBed`.
151 *
152 * In the following code snippet, we are configuring the TestBed with two imports.
153 * The `Ng2AppModule` is the Angular part of our hybrid application and the `ng1AppModule` is the
154 * AngularJS part.
155 *
156 * <code-example path="upgrade/static/ts/full/module.spec.ts" region="angular-setup"></code-example>
157 *
158 * Once this is done we can get hold of services via the Angular `Injector` as normal.
159 * Services that are (or have dependencies on) an upgraded AngularJS service, will be instantiated
160 * as needed by the AngularJS `$injector`.
161 *
162 * In the following code snippet, `HeroesService` is an Angular service that depends upon an
163 * AngularJS service, `titleCase`.
164 *
165 * <code-example path="upgrade/static/ts/full/module.spec.ts" region="angular-spec"></code-example>
166 *
167 * <div class="alert is-important">
168 *
169 * This helper is for testing services not Components.
170 * For Component testing you must still bootstrap a hybrid app. See `UpgradeModule` or
171 * `downgradeModule` for more information.
172 *
173 * </div>
174 *
175 * <div class="alert is-important">
176 *
177 * The resulting configuration does not wire up AngularJS digests to Zone hooks. It is the
178 * responsibility of the test writer to call `$rootScope.$apply`, as necessary, to trigger
179 * AngularJS handlers of async events from Angular.
180 *
181 * </div>
182 *
183 * <div class="alert is-important">
184 *
185 * The helper sets up global variables to hold the shared Angular and AngularJS injectors.
186 *
187 * * Only call this helper once per spec.
188 * * Do not use `createAngularTestingModule` in the same spec as `createAngularJSTestingModule`.
189 *
190 * </div>
191 *
192 * Here is the example application and its unit tests that use `createAngularTestingModule`
193 * and `createAngularJSTestingModule`.
194 *
195 * <code-tabs>
196 * <code-pane header="module.spec.ts" path="upgrade/static/ts/full/module.spec.ts"></code-pane>
197 * <code-pane header="module.ts" path="upgrade/static/ts/full/module.ts"></code-pane>
198 * </code-tabs>
199 *
200 *
201 * @param angularJSModules a collection of the names of AngularJS modules to include in the
202 * configuration.
203 * @param [strictDi] whether the AngularJS injector should have `strictDI` enabled.
204 *
205 * @publicApi
206 */
207 function createAngularTestingModule(angularJSModules, strictDi) {
208 module_('$$angularJSTestingModule', angularJSModules)
209 .constant(UPGRADE_APP_TYPE_KEY, 2 /* Static */)
210 .factory(INJECTOR_KEY, function () { return injector$1; });
211 $injector = injector(['ng', '$$angularJSTestingModule'], strictDi);
212 return AngularTestingModule;
213 }
214
215 /**
216 * @license
217 * Copyright Google LLC All Rights Reserved.
218 *
219 * Use of this source code is governed by an MIT-style license that can be
220 * found in the LICENSE file at https://angular.io/license
221 */
222 /**
223 * A helper function to use when unit testing AngularJS services that depend upon downgraded Angular
224 * services.
225 *
226 * This function returns an AngularJS module that is configured to wire up the AngularJS and Angular
227 * injectors without the need to actually bootstrap a hybrid application.
228 * This makes it simpler and faster to unit test services.
229 *
230 * Use the returned AngularJS module in a call to
231 * [`angular.mocks.module`](https://docs.angularjs.org/api/ngMock/function/angular.mock.module) to
232 * include this module in the unit test injector.
233 *
234 * In the following code snippet, we are configuring the `$injector` with two modules:
235 * The AngularJS `ng1AppModule`, which is the AngularJS part of our hybrid application and the
236 * `Ng2AppModule`, which is the Angular part.
237 *
238 * <code-example path="upgrade/static/ts/full/module.spec.ts"
239 * region="angularjs-setup"></code-example>
240 *
241 * Once this is done we can get hold of services via the AngularJS `$injector` as normal.
242 * Services that are (or have dependencies on) a downgraded Angular service, will be instantiated as
243 * needed by the Angular root `Injector`.
244 *
245 * In the following code snippet, `heroesService` is a downgraded Angular service that we are
246 * accessing from AngularJS.
247 *
248 * <code-example path="upgrade/static/ts/full/module.spec.ts"
249 * region="angularjs-spec"></code-example>
250 *
251 * <div class="alert is-important">
252 *
253 * This helper is for testing services not components.
254 * For Component testing you must still bootstrap a hybrid app. See `UpgradeModule` or
255 * `downgradeModule` for more information.
256 *
257 * </div>
258 *
259 * <div class="alert is-important">
260 *
261 * The resulting configuration does not wire up AngularJS digests to Zone hooks. It is the
262 * responsibility of the test writer to call `$rootScope.$apply`, as necessary, to trigger
263 * AngularJS handlers of async events from Angular.
264 *
265 * </div>
266 *
267 * <div class="alert is-important">
268 *
269 * The helper sets up global variables to hold the shared Angular and AngularJS injectors.
270 *
271 * * Only call this helper once per spec.
272 * * Do not use `createAngularJSTestingModule` in the same spec as `createAngularTestingModule`.
273 *
274 * </div>
275 *
276 * Here is the example application and its unit tests that use `createAngularTestingModule`
277 * and `createAngularJSTestingModule`.
278 *
279 * <code-tabs>
280 * <code-pane header="module.spec.ts" path="upgrade/static/ts/full/module.spec.ts"></code-pane>
281 * <code-pane header="module.ts" path="upgrade/static/ts/full/module.ts"></code-pane>
282 * </code-tabs>
283 *
284 *
285 * @param angularModules a collection of Angular modules to include in the configuration.
286 *
287 * @publicApi
288 */
289 function createAngularJSTestingModule(angularModules) {
290 return module_('$$angularJSTestingModule', [])
291 .constant(UPGRADE_APP_TYPE_KEY, 2 /* Static */)
292 .factory(INJECTOR_KEY, [
293 $INJECTOR,
294 function ($injector) {
295 testing.TestBed.configureTestingModule({
296 imports: angularModules,
297 providers: [{ provide: $INJECTOR, useValue: $injector }]
298 });
299 return testing.TestBed.inject(core.Injector);
300 }
301 ])
302 .name;
303 }
304
305 /**
306 * @license
307 * Copyright Google LLC All Rights Reserved.
308 *
309 * Use of this source code is governed by an MIT-style license that can be
310 * found in the LICENSE file at https://angular.io/license
311 */
312
313 /**
314 * @license
315 * Copyright Google LLC All Rights Reserved.
316 *
317 * Use of this source code is governed by an MIT-style license that can be
318 * found in the LICENSE file at https://angular.io/license
319 */
320
321 /**
322 * Generated bundle index. Do not edit.
323 */
324
325 exports.createAngularJSTestingModule = createAngularJSTestingModule;
326 exports.createAngularTestingModule = createAngularTestingModule;
327 exports.ɵangular_packages_upgrade_static_testing_testing_a = module_;
328 exports.ɵangular_packages_upgrade_static_testing_testing_b = UPGRADE_APP_TYPE_KEY;
329 exports.ɵangular_packages_upgrade_static_testing_testing_d = INJECTOR_KEY;
330
331 Object.defineProperty(exports, '__esModule', { value: true });
332
333})));
334//# sourceMappingURL=upgrade-static-testing.umd.js.map