1 | /**
|
---|
2 | * @license Angular v12.2.9
|
---|
3 | * (c) 2010-2021 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/compiler')) :
|
---|
9 | typeof define === 'function' && define.amd ? define('@angular/core/testing', ['exports', '@angular/core', '@angular/compiler'], factory) :
|
---|
10 | (global = global || self, factory((global.ng = global.ng || {}, global.ng.core = global.ng.core || {}, global.ng.core.testing = {}), global.ng.core, global.ng.compiler));
|
---|
11 | }(this, (function (exports, core, compiler) { '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 | /**
|
---|
21 | * Wraps a test function in an asynchronous test zone. The test will automatically
|
---|
22 | * complete when all asynchronous calls within this zone are done. Can be used
|
---|
23 | * to wrap an {@link inject} call.
|
---|
24 | *
|
---|
25 | * Example:
|
---|
26 | *
|
---|
27 | * ```
|
---|
28 | * it('...', waitForAsync(inject([AClass], (object) => {
|
---|
29 | * object.doSomething.then(() => {
|
---|
30 | * expect(...);
|
---|
31 | * })
|
---|
32 | * });
|
---|
33 | * ```
|
---|
34 | *
|
---|
35 | * @publicApi
|
---|
36 | */
|
---|
37 | function waitForAsync(fn) {
|
---|
38 | var _Zone = typeof Zone !== 'undefined' ? Zone : null;
|
---|
39 | if (!_Zone) {
|
---|
40 | return function () {
|
---|
41 | return Promise.reject('Zone is needed for the waitForAsync() test helper but could not be found. ' +
|
---|
42 | 'Please make sure that your environment includes zone.js');
|
---|
43 | };
|
---|
44 | }
|
---|
45 | var asyncTest = _Zone && _Zone[_Zone.__symbol__('asyncTest')];
|
---|
46 | if (typeof asyncTest === 'function') {
|
---|
47 | return asyncTest(fn);
|
---|
48 | }
|
---|
49 | return function () {
|
---|
50 | return Promise.reject('zone-testing.js is needed for the async() test helper but could not be found. ' +
|
---|
51 | 'Please make sure that your environment includes zone.js/testing');
|
---|
52 | };
|
---|
53 | }
|
---|
54 | /**
|
---|
55 | * @deprecated use `waitForAsync()`, (expected removal in v12)
|
---|
56 | * @see {@link waitForAsync}
|
---|
57 | * @publicApi
|
---|
58 | * */
|
---|
59 | function async(fn) {
|
---|
60 | return waitForAsync(fn);
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * @license
|
---|
65 | * Copyright Google LLC All Rights Reserved.
|
---|
66 | *
|
---|
67 | * Use of this source code is governed by an MIT-style license that can be
|
---|
68 | * found in the LICENSE file at https://angular.io/license
|
---|
69 | */
|
---|
70 | /**
|
---|
71 | * Fixture for debugging and testing a component.
|
---|
72 | *
|
---|
73 | * @publicApi
|
---|
74 | */
|
---|
75 | var ComponentFixture = /** @class */ (function () {
|
---|
76 | function ComponentFixture(componentRef, ngZone, _autoDetect) {
|
---|
77 | var _this = this;
|
---|
78 | this.componentRef = componentRef;
|
---|
79 | this.ngZone = ngZone;
|
---|
80 | this._autoDetect = _autoDetect;
|
---|
81 | this._isStable = true;
|
---|
82 | this._isDestroyed = false;
|
---|
83 | this._resolve = null;
|
---|
84 | this._promise = null;
|
---|
85 | this._onUnstableSubscription = null;
|
---|
86 | this._onStableSubscription = null;
|
---|
87 | this._onMicrotaskEmptySubscription = null;
|
---|
88 | this._onErrorSubscription = null;
|
---|
89 | this.changeDetectorRef = componentRef.changeDetectorRef;
|
---|
90 | this.elementRef = componentRef.location;
|
---|
91 | this.debugElement = core.getDebugNode(this.elementRef.nativeElement);
|
---|
92 | this.componentInstance = componentRef.instance;
|
---|
93 | this.nativeElement = this.elementRef.nativeElement;
|
---|
94 | this.componentRef = componentRef;
|
---|
95 | this.ngZone = ngZone;
|
---|
96 | if (ngZone) {
|
---|
97 | // Create subscriptions outside the NgZone so that the callbacks run oustide
|
---|
98 | // of NgZone.
|
---|
99 | ngZone.runOutsideAngular(function () {
|
---|
100 | _this._onUnstableSubscription = ngZone.onUnstable.subscribe({
|
---|
101 | next: function () {
|
---|
102 | _this._isStable = false;
|
---|
103 | }
|
---|
104 | });
|
---|
105 | _this._onMicrotaskEmptySubscription = ngZone.onMicrotaskEmpty.subscribe({
|
---|
106 | next: function () {
|
---|
107 | if (_this._autoDetect) {
|
---|
108 | // Do a change detection run with checkNoChanges set to true to check
|
---|
109 | // there are no changes on the second run.
|
---|
110 | _this.detectChanges(true);
|
---|
111 | }
|
---|
112 | }
|
---|
113 | });
|
---|
114 | _this._onStableSubscription = ngZone.onStable.subscribe({
|
---|
115 | next: function () {
|
---|
116 | _this._isStable = true;
|
---|
117 | // Check whether there is a pending whenStable() completer to resolve.
|
---|
118 | if (_this._promise !== null) {
|
---|
119 | // If so check whether there are no pending macrotasks before resolving.
|
---|
120 | // Do this check in the next tick so that ngZone gets a chance to update the state of
|
---|
121 | // pending macrotasks.
|
---|
122 | scheduleMicroTask(function () {
|
---|
123 | if (!ngZone.hasPendingMacrotasks) {
|
---|
124 | if (_this._promise !== null) {
|
---|
125 | _this._resolve(true);
|
---|
126 | _this._resolve = null;
|
---|
127 | _this._promise = null;
|
---|
128 | }
|
---|
129 | }
|
---|
130 | });
|
---|
131 | }
|
---|
132 | }
|
---|
133 | });
|
---|
134 | _this._onErrorSubscription = ngZone.onError.subscribe({
|
---|
135 | next: function (error) {
|
---|
136 | throw error;
|
---|
137 | }
|
---|
138 | });
|
---|
139 | });
|
---|
140 | }
|
---|
141 | }
|
---|
142 | ComponentFixture.prototype._tick = function (checkNoChanges) {
|
---|
143 | this.changeDetectorRef.detectChanges();
|
---|
144 | if (checkNoChanges) {
|
---|
145 | this.checkNoChanges();
|
---|
146 | }
|
---|
147 | };
|
---|
148 | /**
|
---|
149 | * Trigger a change detection cycle for the component.
|
---|
150 | */
|
---|
151 | ComponentFixture.prototype.detectChanges = function (checkNoChanges) {
|
---|
152 | var _this = this;
|
---|
153 | if (checkNoChanges === void 0) { checkNoChanges = true; }
|
---|
154 | if (this.ngZone != null) {
|
---|
155 | // Run the change detection inside the NgZone so that any async tasks as part of the change
|
---|
156 | // detection are captured by the zone and can be waited for in isStable.
|
---|
157 | this.ngZone.run(function () {
|
---|
158 | _this._tick(checkNoChanges);
|
---|
159 | });
|
---|
160 | }
|
---|
161 | else {
|
---|
162 | // Running without zone. Just do the change detection.
|
---|
163 | this._tick(checkNoChanges);
|
---|
164 | }
|
---|
165 | };
|
---|
166 | /**
|
---|
167 | * Do a change detection run to make sure there were no changes.
|
---|
168 | */
|
---|
169 | ComponentFixture.prototype.checkNoChanges = function () {
|
---|
170 | this.changeDetectorRef.checkNoChanges();
|
---|
171 | };
|
---|
172 | /**
|
---|
173 | * Set whether the fixture should autodetect changes.
|
---|
174 | *
|
---|
175 | * Also runs detectChanges once so that any existing change is detected.
|
---|
176 | */
|
---|
177 | ComponentFixture.prototype.autoDetectChanges = function (autoDetect) {
|
---|
178 | if (autoDetect === void 0) { autoDetect = true; }
|
---|
179 | if (this.ngZone == null) {
|
---|
180 | throw new Error('Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set');
|
---|
181 | }
|
---|
182 | this._autoDetect = autoDetect;
|
---|
183 | this.detectChanges();
|
---|
184 | };
|
---|
185 | /**
|
---|
186 | * Return whether the fixture is currently stable or has async tasks that have not been completed
|
---|
187 | * yet.
|
---|
188 | */
|
---|
189 | ComponentFixture.prototype.isStable = function () {
|
---|
190 | return this._isStable && !this.ngZone.hasPendingMacrotasks;
|
---|
191 | };
|
---|
192 | /**
|
---|
193 | * Get a promise that resolves when the fixture is stable.
|
---|
194 | *
|
---|
195 | * This can be used to resume testing after events have triggered asynchronous activity or
|
---|
196 | * asynchronous change detection.
|
---|
197 | */
|
---|
198 | ComponentFixture.prototype.whenStable = function () {
|
---|
199 | var _this = this;
|
---|
200 | if (this.isStable()) {
|
---|
201 | return Promise.resolve(false);
|
---|
202 | }
|
---|
203 | else if (this._promise !== null) {
|
---|
204 | return this._promise;
|
---|
205 | }
|
---|
206 | else {
|
---|
207 | this._promise = new Promise(function (res) {
|
---|
208 | _this._resolve = res;
|
---|
209 | });
|
---|
210 | return this._promise;
|
---|
211 | }
|
---|
212 | };
|
---|
213 | ComponentFixture.prototype._getRenderer = function () {
|
---|
214 | if (this._renderer === undefined) {
|
---|
215 | this._renderer = this.componentRef.injector.get(core.RendererFactory2, null);
|
---|
216 | }
|
---|
217 | return this._renderer;
|
---|
218 | };
|
---|
219 | /**
|
---|
220 | * Get a promise that resolves when the ui state is stable following animations.
|
---|
221 | */
|
---|
222 | ComponentFixture.prototype.whenRenderingDone = function () {
|
---|
223 | var renderer = this._getRenderer();
|
---|
224 | if (renderer && renderer.whenRenderingDone) {
|
---|
225 | return renderer.whenRenderingDone();
|
---|
226 | }
|
---|
227 | return this.whenStable();
|
---|
228 | };
|
---|
229 | /**
|
---|
230 | * Trigger component destruction.
|
---|
231 | */
|
---|
232 | ComponentFixture.prototype.destroy = function () {
|
---|
233 | if (!this._isDestroyed) {
|
---|
234 | this.componentRef.destroy();
|
---|
235 | if (this._onUnstableSubscription != null) {
|
---|
236 | this._onUnstableSubscription.unsubscribe();
|
---|
237 | this._onUnstableSubscription = null;
|
---|
238 | }
|
---|
239 | if (this._onStableSubscription != null) {
|
---|
240 | this._onStableSubscription.unsubscribe();
|
---|
241 | this._onStableSubscription = null;
|
---|
242 | }
|
---|
243 | if (this._onMicrotaskEmptySubscription != null) {
|
---|
244 | this._onMicrotaskEmptySubscription.unsubscribe();
|
---|
245 | this._onMicrotaskEmptySubscription = null;
|
---|
246 | }
|
---|
247 | if (this._onErrorSubscription != null) {
|
---|
248 | this._onErrorSubscription.unsubscribe();
|
---|
249 | this._onErrorSubscription = null;
|
---|
250 | }
|
---|
251 | this._isDestroyed = true;
|
---|
252 | }
|
---|
253 | };
|
---|
254 | return ComponentFixture;
|
---|
255 | }());
|
---|
256 | function scheduleMicroTask(fn) {
|
---|
257 | Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
|
---|
258 | }
|
---|
259 |
|
---|
260 | /**
|
---|
261 | * @license
|
---|
262 | * Copyright Google LLC All Rights Reserved.
|
---|
263 | *
|
---|
264 | * Use of this source code is governed by an MIT-style license that can be
|
---|
265 | * found in the LICENSE file at https://angular.io/license
|
---|
266 | */
|
---|
267 | var _Zone = typeof Zone !== 'undefined' ? Zone : null;
|
---|
268 | var fakeAsyncTestModule = _Zone && _Zone[_Zone.__symbol__('fakeAsyncTest')];
|
---|
269 | var fakeAsyncTestModuleNotLoadedErrorMessage = "zone-testing.js is needed for the fakeAsync() test helper but could not be found.\n Please make sure that your environment includes zone.js/testing";
|
---|
270 | /**
|
---|
271 | * Clears out the shared fake async zone for a test.
|
---|
272 | * To be called in a global `beforeEach`.
|
---|
273 | *
|
---|
274 | * @publicApi
|
---|
275 | */
|
---|
276 | function resetFakeAsyncZone() {
|
---|
277 | if (fakeAsyncTestModule) {
|
---|
278 | return fakeAsyncTestModule.resetFakeAsyncZone();
|
---|
279 | }
|
---|
280 | throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
|
---|
281 | }
|
---|
282 | /**
|
---|
283 | * Wraps a function to be executed in the `fakeAsync` zone:
|
---|
284 | * - Microtasks are manually executed by calling `flushMicrotasks()`.
|
---|
285 | * - Timers are synchronous; `tick()` simulates the asynchronous passage of time.
|
---|
286 | *
|
---|
287 | * If there are any pending timers at the end of the function, an exception is thrown.
|
---|
288 | *
|
---|
289 | * Can be used to wrap `inject()` calls.
|
---|
290 | *
|
---|
291 | * @param fn The function that you want to wrap in the `fakeAysnc` zone.
|
---|
292 | *
|
---|
293 | * @usageNotes
|
---|
294 | * ### Example
|
---|
295 | *
|
---|
296 | * {@example core/testing/ts/fake_async.ts region='basic'}
|
---|
297 | *
|
---|
298 | *
|
---|
299 | * @returns The function wrapped to be executed in the `fakeAsync` zone.
|
---|
300 | * Any arguments passed when calling this returned function will be passed through to the `fn`
|
---|
301 | * function in the parameters when it is called.
|
---|
302 | *
|
---|
303 | * @publicApi
|
---|
304 | */
|
---|
305 | function fakeAsync(fn) {
|
---|
306 | if (fakeAsyncTestModule) {
|
---|
307 | return fakeAsyncTestModule.fakeAsync(fn);
|
---|
308 | }
|
---|
309 | throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
|
---|
310 | }
|
---|
311 | /**
|
---|
312 | * Simulates the asynchronous passage of time for the timers in the `fakeAsync` zone.
|
---|
313 | *
|
---|
314 | * The microtasks queue is drained at the very start of this function and after any timer callback
|
---|
315 | * has been executed.
|
---|
316 | *
|
---|
317 | * @param millis The number of milliseconds to advance the virtual timer.
|
---|
318 | * @param tickOptions The options to pass to the `tick()` function.
|
---|
319 | *
|
---|
320 | * @usageNotes
|
---|
321 | *
|
---|
322 | * The `tick()` option is a flag called `processNewMacroTasksSynchronously`,
|
---|
323 | * which determines whether or not to invoke new macroTasks.
|
---|
324 | *
|
---|
325 | * If you provide a `tickOptions` object, but do not specify a
|
---|
326 | * `processNewMacroTasksSynchronously` property (`tick(100, {})`),
|
---|
327 | * then `processNewMacroTasksSynchronously` defaults to true.
|
---|
328 | *
|
---|
329 | * If you omit the `tickOptions` parameter (`tick(100))`), then
|
---|
330 | * `tickOptions` defaults to `{processNewMacroTasksSynchronously: true}`.
|
---|
331 | *
|
---|
332 | * ### Example
|
---|
333 | *
|
---|
334 | * {@example core/testing/ts/fake_async.ts region='basic'}
|
---|
335 | *
|
---|
336 | * The following example includes a nested timeout (new macroTask), and
|
---|
337 | * the `tickOptions` parameter is allowed to default. In this case,
|
---|
338 | * `processNewMacroTasksSynchronously` defaults to true, and the nested
|
---|
339 | * function is executed on each tick.
|
---|
340 | *
|
---|
341 | * ```
|
---|
342 | * it ('test with nested setTimeout', fakeAsync(() => {
|
---|
343 | * let nestedTimeoutInvoked = false;
|
---|
344 | * function funcWithNestedTimeout() {
|
---|
345 | * setTimeout(() => {
|
---|
346 | * nestedTimeoutInvoked = true;
|
---|
347 | * });
|
---|
348 | * };
|
---|
349 | * setTimeout(funcWithNestedTimeout);
|
---|
350 | * tick();
|
---|
351 | * expect(nestedTimeoutInvoked).toBe(true);
|
---|
352 | * }));
|
---|
353 | * ```
|
---|
354 | *
|
---|
355 | * In the following case, `processNewMacroTasksSynchronously` is explicitly
|
---|
356 | * set to false, so the nested timeout function is not invoked.
|
---|
357 | *
|
---|
358 | * ```
|
---|
359 | * it ('test with nested setTimeout', fakeAsync(() => {
|
---|
360 | * let nestedTimeoutInvoked = false;
|
---|
361 | * function funcWithNestedTimeout() {
|
---|
362 | * setTimeout(() => {
|
---|
363 | * nestedTimeoutInvoked = true;
|
---|
364 | * });
|
---|
365 | * };
|
---|
366 | * setTimeout(funcWithNestedTimeout);
|
---|
367 | * tick(0, {processNewMacroTasksSynchronously: false});
|
---|
368 | * expect(nestedTimeoutInvoked).toBe(false);
|
---|
369 | * }));
|
---|
370 | * ```
|
---|
371 | *
|
---|
372 | *
|
---|
373 | * @publicApi
|
---|
374 | */
|
---|
375 | function tick(millis, tickOptions) {
|
---|
376 | if (millis === void 0) { millis = 0; }
|
---|
377 | if (tickOptions === void 0) { tickOptions = {
|
---|
378 | processNewMacroTasksSynchronously: true
|
---|
379 | }; }
|
---|
380 | if (fakeAsyncTestModule) {
|
---|
381 | return fakeAsyncTestModule.tick(millis, tickOptions);
|
---|
382 | }
|
---|
383 | throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
|
---|
384 | }
|
---|
385 | /**
|
---|
386 | * Simulates the asynchronous passage of time for the timers in the `fakeAsync` zone by
|
---|
387 | * draining the macrotask queue until it is empty.
|
---|
388 | *
|
---|
389 | * @param maxTurns The maximum number of times the scheduler attempts to clear its queue before
|
---|
390 | * throwing an error.
|
---|
391 | * @returns The simulated time elapsed, in milliseconds.
|
---|
392 | *
|
---|
393 | * @publicApi
|
---|
394 | */
|
---|
395 | function flush(maxTurns) {
|
---|
396 | if (fakeAsyncTestModule) {
|
---|
397 | return fakeAsyncTestModule.flush(maxTurns);
|
---|
398 | }
|
---|
399 | throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
|
---|
400 | }
|
---|
401 | /**
|
---|
402 | * Discard all remaining periodic tasks.
|
---|
403 | *
|
---|
404 | * @publicApi
|
---|
405 | */
|
---|
406 | function discardPeriodicTasks() {
|
---|
407 | if (fakeAsyncTestModule) {
|
---|
408 | return fakeAsyncTestModule.discardPeriodicTasks();
|
---|
409 | }
|
---|
410 | throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
|
---|
411 | }
|
---|
412 | /**
|
---|
413 | * Flush any pending microtasks.
|
---|
414 | *
|
---|
415 | * @publicApi
|
---|
416 | */
|
---|
417 | function flushMicrotasks() {
|
---|
418 | if (fakeAsyncTestModule) {
|
---|
419 | return fakeAsyncTestModule.flushMicrotasks();
|
---|
420 | }
|
---|
421 | throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
|
---|
422 | }
|
---|
423 |
|
---|
424 | /*! *****************************************************************************
|
---|
425 | Copyright (c) Microsoft Corporation.
|
---|
426 |
|
---|
427 | Permission to use, copy, modify, and/or distribute this software for any
|
---|
428 | purpose with or without fee is hereby granted.
|
---|
429 |
|
---|
430 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
---|
431 | REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
---|
432 | AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
---|
433 | INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
---|
434 | LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
---|
435 | OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
---|
436 | PERFORMANCE OF THIS SOFTWARE.
|
---|
437 | ***************************************************************************** */
|
---|
438 | /* global Reflect, Promise */
|
---|
439 | var extendStatics = function (d, b) {
|
---|
440 | extendStatics = Object.setPrototypeOf ||
|
---|
441 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
---|
442 | function (d, b) { for (var p in b)
|
---|
443 | if (Object.prototype.hasOwnProperty.call(b, p))
|
---|
444 | d[p] = b[p]; };
|
---|
445 | return extendStatics(d, b);
|
---|
446 | };
|
---|
447 | function __extends(d, b) {
|
---|
448 | if (typeof b !== "function" && b !== null)
|
---|
449 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
---|
450 | extendStatics(d, b);
|
---|
451 | function __() { this.constructor = d; }
|
---|
452 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
---|
453 | }
|
---|
454 | var __assign = function () {
|
---|
455 | __assign = Object.assign || function __assign(t) {
|
---|
456 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
---|
457 | s = arguments[i];
|
---|
458 | for (var p in s)
|
---|
459 | if (Object.prototype.hasOwnProperty.call(s, p))
|
---|
460 | t[p] = s[p];
|
---|
461 | }
|
---|
462 | return t;
|
---|
463 | };
|
---|
464 | return __assign.apply(this, arguments);
|
---|
465 | };
|
---|
466 | function __rest(s, e) {
|
---|
467 | var t = {};
|
---|
468 | for (var p in s)
|
---|
469 | if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
---|
470 | t[p] = s[p];
|
---|
471 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
---|
472 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
---|
473 | if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
---|
474 | t[p[i]] = s[p[i]];
|
---|
475 | }
|
---|
476 | return t;
|
---|
477 | }
|
---|
478 | function __decorate(decorators, target, key, desc) {
|
---|
479 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
---|
480 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
---|
481 | r = Reflect.decorate(decorators, target, key, desc);
|
---|
482 | else
|
---|
483 | for (var i = decorators.length - 1; i >= 0; i--)
|
---|
484 | if (d = decorators[i])
|
---|
485 | r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
---|
486 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
---|
487 | }
|
---|
488 | function __param(paramIndex, decorator) {
|
---|
489 | return function (target, key) { decorator(target, key, paramIndex); };
|
---|
490 | }
|
---|
491 | function __metadata(metadataKey, metadataValue) {
|
---|
492 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
|
---|
493 | return Reflect.metadata(metadataKey, metadataValue);
|
---|
494 | }
|
---|
495 | function __awaiter(thisArg, _arguments, P, generator) {
|
---|
496 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
---|
497 | return new (P || (P = Promise))(function (resolve, reject) {
|
---|
498 | function fulfilled(value) { try {
|
---|
499 | step(generator.next(value));
|
---|
500 | }
|
---|
501 | catch (e) {
|
---|
502 | reject(e);
|
---|
503 | } }
|
---|
504 | function rejected(value) { try {
|
---|
505 | step(generator["throw"](value));
|
---|
506 | }
|
---|
507 | catch (e) {
|
---|
508 | reject(e);
|
---|
509 | } }
|
---|
510 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
---|
511 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
---|
512 | });
|
---|
513 | }
|
---|
514 | function __generator(thisArg, body) {
|
---|
515 | var _ = { label: 0, sent: function () { if (t[0] & 1)
|
---|
516 | throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
---|
517 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
|
---|
518 | function verb(n) { return function (v) { return step([n, v]); }; }
|
---|
519 | function step(op) {
|
---|
520 | if (f)
|
---|
521 | throw new TypeError("Generator is already executing.");
|
---|
522 | while (_)
|
---|
523 | try {
|
---|
524 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
---|
525 | return t;
|
---|
526 | if (y = 0, t)
|
---|
527 | op = [op[0] & 2, t.value];
|
---|
528 | switch (op[0]) {
|
---|
529 | case 0:
|
---|
530 | case 1:
|
---|
531 | t = op;
|
---|
532 | break;
|
---|
533 | case 4:
|
---|
534 | _.label++;
|
---|
535 | return { value: op[1], done: false };
|
---|
536 | case 5:
|
---|
537 | _.label++;
|
---|
538 | y = op[1];
|
---|
539 | op = [0];
|
---|
540 | continue;
|
---|
541 | case 7:
|
---|
542 | op = _.ops.pop();
|
---|
543 | _.trys.pop();
|
---|
544 | continue;
|
---|
545 | default:
|
---|
546 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
---|
547 | _ = 0;
|
---|
548 | continue;
|
---|
549 | }
|
---|
550 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
|
---|
551 | _.label = op[1];
|
---|
552 | break;
|
---|
553 | }
|
---|
554 | if (op[0] === 6 && _.label < t[1]) {
|
---|
555 | _.label = t[1];
|
---|
556 | t = op;
|
---|
557 | break;
|
---|
558 | }
|
---|
559 | if (t && _.label < t[2]) {
|
---|
560 | _.label = t[2];
|
---|
561 | _.ops.push(op);
|
---|
562 | break;
|
---|
563 | }
|
---|
564 | if (t[2])
|
---|
565 | _.ops.pop();
|
---|
566 | _.trys.pop();
|
---|
567 | continue;
|
---|
568 | }
|
---|
569 | op = body.call(thisArg, _);
|
---|
570 | }
|
---|
571 | catch (e) {
|
---|
572 | op = [6, e];
|
---|
573 | y = 0;
|
---|
574 | }
|
---|
575 | finally {
|
---|
576 | f = t = 0;
|
---|
577 | }
|
---|
578 | if (op[0] & 5)
|
---|
579 | throw op[1];
|
---|
580 | return { value: op[0] ? op[1] : void 0, done: true };
|
---|
581 | }
|
---|
582 | }
|
---|
583 | var __createBinding = Object.create ? (function (o, m, k, k2) {
|
---|
584 | if (k2 === undefined)
|
---|
585 | k2 = k;
|
---|
586 | Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
---|
587 | }) : (function (o, m, k, k2) {
|
---|
588 | if (k2 === undefined)
|
---|
589 | k2 = k;
|
---|
590 | o[k2] = m[k];
|
---|
591 | });
|
---|
592 | function __exportStar(m, o) {
|
---|
593 | for (var p in m)
|
---|
594 | if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
|
---|
595 | __createBinding(o, m, p);
|
---|
596 | }
|
---|
597 | function __values(o) {
|
---|
598 | var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
---|
599 | if (m)
|
---|
600 | return m.call(o);
|
---|
601 | if (o && typeof o.length === "number")
|
---|
602 | return {
|
---|
603 | next: function () {
|
---|
604 | if (o && i >= o.length)
|
---|
605 | o = void 0;
|
---|
606 | return { value: o && o[i++], done: !o };
|
---|
607 | }
|
---|
608 | };
|
---|
609 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
---|
610 | }
|
---|
611 | function __read(o, n) {
|
---|
612 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
---|
613 | if (!m)
|
---|
614 | return o;
|
---|
615 | var i = m.call(o), r, ar = [], e;
|
---|
616 | try {
|
---|
617 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
|
---|
618 | ar.push(r.value);
|
---|
619 | }
|
---|
620 | catch (error) {
|
---|
621 | e = { error: error };
|
---|
622 | }
|
---|
623 | finally {
|
---|
624 | try {
|
---|
625 | if (r && !r.done && (m = i["return"]))
|
---|
626 | m.call(i);
|
---|
627 | }
|
---|
628 | finally {
|
---|
629 | if (e)
|
---|
630 | throw e.error;
|
---|
631 | }
|
---|
632 | }
|
---|
633 | return ar;
|
---|
634 | }
|
---|
635 | /** @deprecated */
|
---|
636 | function __spread() {
|
---|
637 | for (var ar = [], i = 0; i < arguments.length; i++)
|
---|
638 | ar = ar.concat(__read(arguments[i]));
|
---|
639 | return ar;
|
---|
640 | }
|
---|
641 | /** @deprecated */
|
---|
642 | function __spreadArrays() {
|
---|
643 | for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
---|
644 | s += arguments[i].length;
|
---|
645 | for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
---|
646 | for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
---|
647 | r[k] = a[j];
|
---|
648 | return r;
|
---|
649 | }
|
---|
650 | function __spreadArray(to, from, pack) {
|
---|
651 | if (pack || arguments.length === 2)
|
---|
652 | for (var i = 0, l = from.length, ar; i < l; i++) {
|
---|
653 | if (ar || !(i in from)) {
|
---|
654 | if (!ar)
|
---|
655 | ar = Array.prototype.slice.call(from, 0, i);
|
---|
656 | ar[i] = from[i];
|
---|
657 | }
|
---|
658 | }
|
---|
659 | return to.concat(ar || Array.prototype.slice.call(from));
|
---|
660 | }
|
---|
661 | function __await(v) {
|
---|
662 | return this instanceof __await ? (this.v = v, this) : new __await(v);
|
---|
663 | }
|
---|
664 | function __asyncGenerator(thisArg, _arguments, generator) {
|
---|
665 | if (!Symbol.asyncIterator)
|
---|
666 | throw new TypeError("Symbol.asyncIterator is not defined.");
|
---|
667 | var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
---|
668 | return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
---|
669 | function verb(n) { if (g[n])
|
---|
670 | i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
---|
671 | function resume(n, v) { try {
|
---|
672 | step(g[n](v));
|
---|
673 | }
|
---|
674 | catch (e) {
|
---|
675 | settle(q[0][3], e);
|
---|
676 | } }
|
---|
677 | function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
---|
678 | function fulfill(value) { resume("next", value); }
|
---|
679 | function reject(value) { resume("throw", value); }
|
---|
680 | function settle(f, v) { if (f(v), q.shift(), q.length)
|
---|
681 | resume(q[0][0], q[0][1]); }
|
---|
682 | }
|
---|
683 | function __asyncDelegator(o) {
|
---|
684 | var i, p;
|
---|
685 | return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
|
---|
686 | function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
|
---|
687 | }
|
---|
688 | function __asyncValues(o) {
|
---|
689 | if (!Symbol.asyncIterator)
|
---|
690 | throw new TypeError("Symbol.asyncIterator is not defined.");
|
---|
691 | var m = o[Symbol.asyncIterator], i;
|
---|
692 | return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
---|
693 | function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
---|
694 | function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
|
---|
695 | }
|
---|
696 | function __makeTemplateObject(cooked, raw) {
|
---|
697 | if (Object.defineProperty) {
|
---|
698 | Object.defineProperty(cooked, "raw", { value: raw });
|
---|
699 | }
|
---|
700 | else {
|
---|
701 | cooked.raw = raw;
|
---|
702 | }
|
---|
703 | return cooked;
|
---|
704 | }
|
---|
705 | ;
|
---|
706 | var __setModuleDefault = Object.create ? (function (o, v) {
|
---|
707 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
---|
708 | }) : function (o, v) {
|
---|
709 | o["default"] = v;
|
---|
710 | };
|
---|
711 | function __importStar(mod) {
|
---|
712 | if (mod && mod.__esModule)
|
---|
713 | return mod;
|
---|
714 | var result = {};
|
---|
715 | if (mod != null)
|
---|
716 | for (var k in mod)
|
---|
717 | if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
---|
718 | __createBinding(result, mod, k);
|
---|
719 | __setModuleDefault(result, mod);
|
---|
720 | return result;
|
---|
721 | }
|
---|
722 | function __importDefault(mod) {
|
---|
723 | return (mod && mod.__esModule) ? mod : { default: mod };
|
---|
724 | }
|
---|
725 | function __classPrivateFieldGet(receiver, state, kind, f) {
|
---|
726 | if (kind === "a" && !f)
|
---|
727 | throw new TypeError("Private accessor was defined without a getter");
|
---|
728 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
---|
729 | throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
---|
730 | return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
---|
731 | }
|
---|
732 | function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
---|
733 | if (kind === "m")
|
---|
734 | throw new TypeError("Private method is not writable");
|
---|
735 | if (kind === "a" && !f)
|
---|
736 | throw new TypeError("Private accessor was defined without a setter");
|
---|
737 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
|
---|
738 | throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
---|
739 | return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
---|
740 | }
|
---|
741 |
|
---|
742 | /**
|
---|
743 | * @license
|
---|
744 | * Copyright Google LLC All Rights Reserved.
|
---|
745 | *
|
---|
746 | * Use of this source code is governed by an MIT-style license that can be
|
---|
747 | * found in the LICENSE file at https://angular.io/license
|
---|
748 | */
|
---|
749 | /**
|
---|
750 | * Used to resolve resource URLs on `@Component` when used with JIT compilation.
|
---|
751 | *
|
---|
752 | * Example:
|
---|
753 | * ```
|
---|
754 | * @Component({
|
---|
755 | * selector: 'my-comp',
|
---|
756 | * templateUrl: 'my-comp.html', // This requires asynchronous resolution
|
---|
757 | * })
|
---|
758 | * class MyComponent{
|
---|
759 | * }
|
---|
760 | *
|
---|
761 | * // Calling `renderComponent` will fail because `renderComponent` is a synchronous process
|
---|
762 | * // and `MyComponent`'s `@Component.templateUrl` needs to be resolved asynchronously.
|
---|
763 | *
|
---|
764 | * // Calling `resolveComponentResources()` will resolve `@Component.templateUrl` into
|
---|
765 | * // `@Component.template`, which allows `renderComponent` to proceed in a synchronous manner.
|
---|
766 | *
|
---|
767 | * // Use browser's `fetch()` function as the default resource resolution strategy.
|
---|
768 | * resolveComponentResources(fetch).then(() => {
|
---|
769 | * // After resolution all URLs have been converted into `template` strings.
|
---|
770 | * renderComponent(MyComponent);
|
---|
771 | * });
|
---|
772 | *
|
---|
773 | * ```
|
---|
774 | *
|
---|
775 | * NOTE: In AOT the resolution happens during compilation, and so there should be no need
|
---|
776 | * to call this method outside JIT mode.
|
---|
777 | *
|
---|
778 | * @param resourceResolver a function which is responsible for returning a `Promise` to the
|
---|
779 | * contents of the resolved URL. Browser's `fetch()` method is a good default implementation.
|
---|
780 | */
|
---|
781 | function resolveComponentResources(resourceResolver) {
|
---|
782 | // Store all promises which are fetching the resources.
|
---|
783 | var componentResolved = [];
|
---|
784 | // Cache so that we don't fetch the same resource more than once.
|
---|
785 | var urlMap = new Map();
|
---|
786 | function cachedResourceResolve(url) {
|
---|
787 | var promise = urlMap.get(url);
|
---|
788 | if (!promise) {
|
---|
789 | var resp = resourceResolver(url);
|
---|
790 | urlMap.set(url, promise = resp.then(unwrapResponse));
|
---|
791 | }
|
---|
792 | return promise;
|
---|
793 | }
|
---|
794 | componentResourceResolutionQueue.forEach(function (component, type) {
|
---|
795 | var promises = [];
|
---|
796 | if (component.templateUrl) {
|
---|
797 | promises.push(cachedResourceResolve(component.templateUrl).then(function (template) {
|
---|
798 | component.template = template;
|
---|
799 | }));
|
---|
800 | }
|
---|
801 | var styleUrls = component.styleUrls;
|
---|
802 | var styles = component.styles || (component.styles = []);
|
---|
803 | var styleOffset = component.styles.length;
|
---|
804 | styleUrls && styleUrls.forEach(function (styleUrl, index) {
|
---|
805 | styles.push(''); // pre-allocate array.
|
---|
806 | promises.push(cachedResourceResolve(styleUrl).then(function (style) {
|
---|
807 | styles[styleOffset + index] = style;
|
---|
808 | styleUrls.splice(styleUrls.indexOf(styleUrl), 1);
|
---|
809 | if (styleUrls.length == 0) {
|
---|
810 | component.styleUrls = undefined;
|
---|
811 | }
|
---|
812 | }));
|
---|
813 | });
|
---|
814 | var fullyResolved = Promise.all(promises).then(function () { return componentDefResolved(type); });
|
---|
815 | componentResolved.push(fullyResolved);
|
---|
816 | });
|
---|
817 | clearResolutionOfComponentResourcesQueue();
|
---|
818 | return Promise.all(componentResolved).then(function () { return undefined; });
|
---|
819 | }
|
---|
820 | var componentResourceResolutionQueue = new Map();
|
---|
821 | // Track when existing ɵcmp for a Type is waiting on resources.
|
---|
822 | var componentDefPendingResolution = new Set();
|
---|
823 | function maybeQueueResolutionOfComponentResources(type, metadata) {
|
---|
824 | if (componentNeedsResolution(metadata)) {
|
---|
825 | componentResourceResolutionQueue.set(type, metadata);
|
---|
826 | componentDefPendingResolution.add(type);
|
---|
827 | }
|
---|
828 | }
|
---|
829 | function isComponentDefPendingResolution(type) {
|
---|
830 | return componentDefPendingResolution.has(type);
|
---|
831 | }
|
---|
832 | function componentNeedsResolution(component) {
|
---|
833 | return !!((component.templateUrl && !component.hasOwnProperty('template')) ||
|
---|
834 | component.styleUrls && component.styleUrls.length);
|
---|
835 | }
|
---|
836 | function clearResolutionOfComponentResourcesQueue() {
|
---|
837 | var old = componentResourceResolutionQueue;
|
---|
838 | componentResourceResolutionQueue = new Map();
|
---|
839 | return old;
|
---|
840 | }
|
---|
841 | function restoreComponentResolutionQueue(queue) {
|
---|
842 | componentDefPendingResolution.clear();
|
---|
843 | queue.forEach(function (_, type) { return componentDefPendingResolution.add(type); });
|
---|
844 | componentResourceResolutionQueue = queue;
|
---|
845 | }
|
---|
846 | function isComponentResourceResolutionQueueEmpty() {
|
---|
847 | return componentResourceResolutionQueue.size === 0;
|
---|
848 | }
|
---|
849 | function unwrapResponse(response) {
|
---|
850 | return typeof response == 'string' ? response : response.text();
|
---|
851 | }
|
---|
852 | function componentDefResolved(type) {
|
---|
853 | componentDefPendingResolution.delete(type);
|
---|
854 | }
|
---|
855 |
|
---|
856 | /**
|
---|
857 | * @license
|
---|
858 | * Copyright Google LLC All Rights Reserved.
|
---|
859 | *
|
---|
860 | * Use of this source code is governed by an MIT-style license that can be
|
---|
861 | * found in the LICENSE file at https://angular.io/license
|
---|
862 | */
|
---|
863 | var _nextReferenceId = 0;
|
---|
864 | var MetadataOverrider = /** @class */ (function () {
|
---|
865 | function MetadataOverrider() {
|
---|
866 | this._references = new Map();
|
---|
867 | }
|
---|
868 | /**
|
---|
869 | * Creates a new instance for the given metadata class
|
---|
870 | * based on an old instance and overrides.
|
---|
871 | */
|
---|
872 | MetadataOverrider.prototype.overrideMetadata = function (metadataClass, oldMetadata, override) {
|
---|
873 | var props = {};
|
---|
874 | if (oldMetadata) {
|
---|
875 | _valueProps(oldMetadata).forEach(function (prop) { return props[prop] = oldMetadata[prop]; });
|
---|
876 | }
|
---|
877 | if (override.set) {
|
---|
878 | if (override.remove || override.add) {
|
---|
879 | throw new Error("Cannot set and add/remove " + core.ɵstringify(metadataClass) + " at the same time!");
|
---|
880 | }
|
---|
881 | setMetadata(props, override.set);
|
---|
882 | }
|
---|
883 | if (override.remove) {
|
---|
884 | removeMetadata(props, override.remove, this._references);
|
---|
885 | }
|
---|
886 | if (override.add) {
|
---|
887 | addMetadata(props, override.add);
|
---|
888 | }
|
---|
889 | return new metadataClass(props);
|
---|
890 | };
|
---|
891 | return MetadataOverrider;
|
---|
892 | }());
|
---|
893 | function removeMetadata(metadata, remove, references) {
|
---|
894 | var removeObjects = new Set();
|
---|
895 | var _loop_1 = function (prop) {
|
---|
896 | var removeValue = remove[prop];
|
---|
897 | if (Array.isArray(removeValue)) {
|
---|
898 | removeValue.forEach(function (value) {
|
---|
899 | removeObjects.add(_propHashKey(prop, value, references));
|
---|
900 | });
|
---|
901 | }
|
---|
902 | else {
|
---|
903 | removeObjects.add(_propHashKey(prop, removeValue, references));
|
---|
904 | }
|
---|
905 | };
|
---|
906 | for (var prop in remove) {
|
---|
907 | _loop_1(prop);
|
---|
908 | }
|
---|
909 | var _loop_2 = function (prop) {
|
---|
910 | var propValue = metadata[prop];
|
---|
911 | if (Array.isArray(propValue)) {
|
---|
912 | metadata[prop] = propValue.filter(function (value) { return !removeObjects.has(_propHashKey(prop, value, references)); });
|
---|
913 | }
|
---|
914 | else {
|
---|
915 | if (removeObjects.has(_propHashKey(prop, propValue, references))) {
|
---|
916 | metadata[prop] = undefined;
|
---|
917 | }
|
---|
918 | }
|
---|
919 | };
|
---|
920 | for (var prop in metadata) {
|
---|
921 | _loop_2(prop);
|
---|
922 | }
|
---|
923 | }
|
---|
924 | function addMetadata(metadata, add) {
|
---|
925 | for (var prop in add) {
|
---|
926 | var addValue = add[prop];
|
---|
927 | var propValue = metadata[prop];
|
---|
928 | if (propValue != null && Array.isArray(propValue)) {
|
---|
929 | metadata[prop] = propValue.concat(addValue);
|
---|
930 | }
|
---|
931 | else {
|
---|
932 | metadata[prop] = addValue;
|
---|
933 | }
|
---|
934 | }
|
---|
935 | }
|
---|
936 | function setMetadata(metadata, set) {
|
---|
937 | for (var prop in set) {
|
---|
938 | metadata[prop] = set[prop];
|
---|
939 | }
|
---|
940 | }
|
---|
941 | function _propHashKey(propName, propValue, references) {
|
---|
942 | var replacer = function (key, value) {
|
---|
943 | if (typeof value === 'function') {
|
---|
944 | value = _serializeReference(value, references);
|
---|
945 | }
|
---|
946 | return value;
|
---|
947 | };
|
---|
948 | return propName + ":" + JSON.stringify(propValue, replacer);
|
---|
949 | }
|
---|
950 | function _serializeReference(ref, references) {
|
---|
951 | var id = references.get(ref);
|
---|
952 | if (!id) {
|
---|
953 | id = "" + core.ɵstringify(ref) + _nextReferenceId++;
|
---|
954 | references.set(ref, id);
|
---|
955 | }
|
---|
956 | return id;
|
---|
957 | }
|
---|
958 | function _valueProps(obj) {
|
---|
959 | var props = [];
|
---|
960 | // regular public props
|
---|
961 | Object.keys(obj).forEach(function (prop) {
|
---|
962 | if (!prop.startsWith('_')) {
|
---|
963 | props.push(prop);
|
---|
964 | }
|
---|
965 | });
|
---|
966 | // getters
|
---|
967 | var proto = obj;
|
---|
968 | while (proto = Object.getPrototypeOf(proto)) {
|
---|
969 | Object.keys(proto).forEach(function (protoProp) {
|
---|
970 | var desc = Object.getOwnPropertyDescriptor(proto, protoProp);
|
---|
971 | if (!protoProp.startsWith('_') && desc && 'get' in desc) {
|
---|
972 | props.push(protoProp);
|
---|
973 | }
|
---|
974 | });
|
---|
975 | }
|
---|
976 | return props;
|
---|
977 | }
|
---|
978 |
|
---|
979 | var reflection = new core.ɵReflectionCapabilities();
|
---|
980 | /**
|
---|
981 | * Allows to override ivy metadata for tests (via the `TestBed`).
|
---|
982 | */
|
---|
983 | var OverrideResolver = /** @class */ (function () {
|
---|
984 | function OverrideResolver() {
|
---|
985 | this.overrides = new Map();
|
---|
986 | this.resolved = new Map();
|
---|
987 | }
|
---|
988 | OverrideResolver.prototype.addOverride = function (type, override) {
|
---|
989 | var overrides = this.overrides.get(type) || [];
|
---|
990 | overrides.push(override);
|
---|
991 | this.overrides.set(type, overrides);
|
---|
992 | this.resolved.delete(type);
|
---|
993 | };
|
---|
994 | OverrideResolver.prototype.setOverrides = function (overrides) {
|
---|
995 | var _this = this;
|
---|
996 | this.overrides.clear();
|
---|
997 | overrides.forEach(function (_a) {
|
---|
998 | var _b = __read(_a, 2), type = _b[0], override = _b[1];
|
---|
999 | _this.addOverride(type, override);
|
---|
1000 | });
|
---|
1001 | };
|
---|
1002 | OverrideResolver.prototype.getAnnotation = function (type) {
|
---|
1003 | var annotations = reflection.annotations(type);
|
---|
1004 | // Try to find the nearest known Type annotation and make sure that this annotation is an
|
---|
1005 | // instance of the type we are looking for, so we can use it for resolution. Note: there might
|
---|
1006 | // be multiple known annotations found due to the fact that Components can extend Directives (so
|
---|
1007 | // both Directive and Component annotations would be present), so we always check if the known
|
---|
1008 | // annotation has the right type.
|
---|
1009 | for (var i = annotations.length - 1; i >= 0; i--) {
|
---|
1010 | var annotation = annotations[i];
|
---|
1011 | var isKnownType = annotation instanceof core.Directive || annotation instanceof core.Component ||
|
---|
1012 | annotation instanceof core.Pipe || annotation instanceof core.NgModule;
|
---|
1013 | if (isKnownType) {
|
---|
1014 | return annotation instanceof this.type ? annotation : null;
|
---|
1015 | }
|
---|
1016 | }
|
---|
1017 | return null;
|
---|
1018 | };
|
---|
1019 | OverrideResolver.prototype.resolve = function (type) {
|
---|
1020 | var _this = this;
|
---|
1021 | var resolved = this.resolved.get(type) || null;
|
---|
1022 | if (!resolved) {
|
---|
1023 | resolved = this.getAnnotation(type);
|
---|
1024 | if (resolved) {
|
---|
1025 | var overrides = this.overrides.get(type);
|
---|
1026 | if (overrides) {
|
---|
1027 | var overrider_1 = new MetadataOverrider();
|
---|
1028 | overrides.forEach(function (override) {
|
---|
1029 | resolved = overrider_1.overrideMetadata(_this.type, resolved, override);
|
---|
1030 | });
|
---|
1031 | }
|
---|
1032 | }
|
---|
1033 | this.resolved.set(type, resolved);
|
---|
1034 | }
|
---|
1035 | return resolved;
|
---|
1036 | };
|
---|
1037 | return OverrideResolver;
|
---|
1038 | }());
|
---|
1039 | var DirectiveResolver = /** @class */ (function (_super) {
|
---|
1040 | __extends(DirectiveResolver, _super);
|
---|
1041 | function DirectiveResolver() {
|
---|
1042 | return _super !== null && _super.apply(this, arguments) || this;
|
---|
1043 | }
|
---|
1044 | Object.defineProperty(DirectiveResolver.prototype, "type", {
|
---|
1045 | get: function () {
|
---|
1046 | return core.Directive;
|
---|
1047 | },
|
---|
1048 | enumerable: false,
|
---|
1049 | configurable: true
|
---|
1050 | });
|
---|
1051 | return DirectiveResolver;
|
---|
1052 | }(OverrideResolver));
|
---|
1053 | var ComponentResolver = /** @class */ (function (_super) {
|
---|
1054 | __extends(ComponentResolver, _super);
|
---|
1055 | function ComponentResolver() {
|
---|
1056 | return _super !== null && _super.apply(this, arguments) || this;
|
---|
1057 | }
|
---|
1058 | Object.defineProperty(ComponentResolver.prototype, "type", {
|
---|
1059 | get: function () {
|
---|
1060 | return core.Component;
|
---|
1061 | },
|
---|
1062 | enumerable: false,
|
---|
1063 | configurable: true
|
---|
1064 | });
|
---|
1065 | return ComponentResolver;
|
---|
1066 | }(OverrideResolver));
|
---|
1067 | var PipeResolver = /** @class */ (function (_super) {
|
---|
1068 | __extends(PipeResolver, _super);
|
---|
1069 | function PipeResolver() {
|
---|
1070 | return _super !== null && _super.apply(this, arguments) || this;
|
---|
1071 | }
|
---|
1072 | Object.defineProperty(PipeResolver.prototype, "type", {
|
---|
1073 | get: function () {
|
---|
1074 | return core.Pipe;
|
---|
1075 | },
|
---|
1076 | enumerable: false,
|
---|
1077 | configurable: true
|
---|
1078 | });
|
---|
1079 | return PipeResolver;
|
---|
1080 | }(OverrideResolver));
|
---|
1081 | var NgModuleResolver = /** @class */ (function (_super) {
|
---|
1082 | __extends(NgModuleResolver, _super);
|
---|
1083 | function NgModuleResolver() {
|
---|
1084 | return _super !== null && _super.apply(this, arguments) || this;
|
---|
1085 | }
|
---|
1086 | Object.defineProperty(NgModuleResolver.prototype, "type", {
|
---|
1087 | get: function () {
|
---|
1088 | return core.NgModule;
|
---|
1089 | },
|
---|
1090 | enumerable: false,
|
---|
1091 | configurable: true
|
---|
1092 | });
|
---|
1093 | return NgModuleResolver;
|
---|
1094 | }(OverrideResolver));
|
---|
1095 |
|
---|
1096 | var TestingModuleOverride;
|
---|
1097 | (function (TestingModuleOverride) {
|
---|
1098 | TestingModuleOverride[TestingModuleOverride["DECLARATION"] = 0] = "DECLARATION";
|
---|
1099 | TestingModuleOverride[TestingModuleOverride["OVERRIDE_TEMPLATE"] = 1] = "OVERRIDE_TEMPLATE";
|
---|
1100 | })(TestingModuleOverride || (TestingModuleOverride = {}));
|
---|
1101 | function isTestingModuleOverride(value) {
|
---|
1102 | return value === TestingModuleOverride.DECLARATION ||
|
---|
1103 | value === TestingModuleOverride.OVERRIDE_TEMPLATE;
|
---|
1104 | }
|
---|
1105 | var R3TestBedCompiler = /** @class */ (function () {
|
---|
1106 | function R3TestBedCompiler(platform, additionalModuleTypes) {
|
---|
1107 | this.platform = platform;
|
---|
1108 | this.additionalModuleTypes = additionalModuleTypes;
|
---|
1109 | this.originalComponentResolutionQueue = null;
|
---|
1110 | // Testing module configuration
|
---|
1111 | this.declarations = [];
|
---|
1112 | this.imports = [];
|
---|
1113 | this.providers = [];
|
---|
1114 | this.schemas = [];
|
---|
1115 | // Queues of components/directives/pipes that should be recompiled.
|
---|
1116 | this.pendingComponents = new Set();
|
---|
1117 | this.pendingDirectives = new Set();
|
---|
1118 | this.pendingPipes = new Set();
|
---|
1119 | // Keep track of all components and directives, so we can patch Providers onto defs later.
|
---|
1120 | this.seenComponents = new Set();
|
---|
1121 | this.seenDirectives = new Set();
|
---|
1122 | // Keep track of overridden modules, so that we can collect all affected ones in the module tree.
|
---|
1123 | this.overriddenModules = new Set();
|
---|
1124 | // Store resolved styles for Components that have template overrides present and `styleUrls`
|
---|
1125 | // defined at the same time.
|
---|
1126 | this.existingComponentStyles = new Map();
|
---|
1127 | this.resolvers = initResolvers();
|
---|
1128 | this.componentToModuleScope = new Map();
|
---|
1129 | // Map that keeps initial version of component/directive/pipe defs in case
|
---|
1130 | // we compile a Type again, thus overriding respective static fields. This is
|
---|
1131 | // required to make sure we restore defs to their initial states between test runs
|
---|
1132 | // TODO: we should support the case with multiple defs on a type
|
---|
1133 | this.initialNgDefs = new Map();
|
---|
1134 | // Array that keeps cleanup operations for initial versions of component/directive/pipe/module
|
---|
1135 | // defs in case TestBed makes changes to the originals.
|
---|
1136 | this.defCleanupOps = [];
|
---|
1137 | this._injector = null;
|
---|
1138 | this.compilerProviders = null;
|
---|
1139 | this.providerOverrides = [];
|
---|
1140 | this.rootProviderOverrides = [];
|
---|
1141 | // Overrides for injectables with `{providedIn: SomeModule}` need to be tracked and added to that
|
---|
1142 | // module's provider list.
|
---|
1143 | this.providerOverridesByModule = new Map();
|
---|
1144 | this.providerOverridesByToken = new Map();
|
---|
1145 | this.moduleProvidersOverridden = new Set();
|
---|
1146 | this.testModuleRef = null;
|
---|
1147 | var DynamicTestModule = /** @class */ (function () {
|
---|
1148 | function DynamicTestModule() {
|
---|
1149 | }
|
---|
1150 | return DynamicTestModule;
|
---|
1151 | }());
|
---|
1152 | this.testModuleType = DynamicTestModule;
|
---|
1153 | }
|
---|
1154 | R3TestBedCompiler.prototype.setCompilerProviders = function (providers) {
|
---|
1155 | this.compilerProviders = providers;
|
---|
1156 | this._injector = null;
|
---|
1157 | };
|
---|
1158 | R3TestBedCompiler.prototype.configureTestingModule = function (moduleDef) {
|
---|
1159 | var _a, _b, _c, _d;
|
---|
1160 | // Enqueue any compilation tasks for the directly declared component.
|
---|
1161 | if (moduleDef.declarations !== undefined) {
|
---|
1162 | this.queueTypeArray(moduleDef.declarations, TestingModuleOverride.DECLARATION);
|
---|
1163 | (_a = this.declarations).push.apply(_a, __spreadArray([], __read(moduleDef.declarations)));
|
---|
1164 | }
|
---|
1165 | // Enqueue any compilation tasks for imported modules.
|
---|
1166 | if (moduleDef.imports !== undefined) {
|
---|
1167 | this.queueTypesFromModulesArray(moduleDef.imports);
|
---|
1168 | (_b = this.imports).push.apply(_b, __spreadArray([], __read(moduleDef.imports)));
|
---|
1169 | }
|
---|
1170 | if (moduleDef.providers !== undefined) {
|
---|
1171 | (_c = this.providers).push.apply(_c, __spreadArray([], __read(moduleDef.providers)));
|
---|
1172 | }
|
---|
1173 | if (moduleDef.schemas !== undefined) {
|
---|
1174 | (_d = this.schemas).push.apply(_d, __spreadArray([], __read(moduleDef.schemas)));
|
---|
1175 | }
|
---|
1176 | };
|
---|
1177 | R3TestBedCompiler.prototype.overrideModule = function (ngModule, override) {
|
---|
1178 | this.overriddenModules.add(ngModule);
|
---|
1179 | // Compile the module right away.
|
---|
1180 | this.resolvers.module.addOverride(ngModule, override);
|
---|
1181 | var metadata = this.resolvers.module.resolve(ngModule);
|
---|
1182 | if (metadata === null) {
|
---|
1183 | throw invalidTypeError(ngModule.name, 'NgModule');
|
---|
1184 | }
|
---|
1185 | this.recompileNgModule(ngModule, metadata);
|
---|
1186 | // At this point, the module has a valid module def (ɵmod), but the override may have introduced
|
---|
1187 | // new declarations or imported modules. Ingest any possible new types and add them to the
|
---|
1188 | // current queue.
|
---|
1189 | this.queueTypesFromModulesArray([ngModule]);
|
---|
1190 | };
|
---|
1191 | R3TestBedCompiler.prototype.overrideComponent = function (component, override) {
|
---|
1192 | this.resolvers.component.addOverride(component, override);
|
---|
1193 | this.pendingComponents.add(component);
|
---|
1194 | };
|
---|
1195 | R3TestBedCompiler.prototype.overrideDirective = function (directive, override) {
|
---|
1196 | this.resolvers.directive.addOverride(directive, override);
|
---|
1197 | this.pendingDirectives.add(directive);
|
---|
1198 | };
|
---|
1199 | R3TestBedCompiler.prototype.overridePipe = function (pipe, override) {
|
---|
1200 | this.resolvers.pipe.addOverride(pipe, override);
|
---|
1201 | this.pendingPipes.add(pipe);
|
---|
1202 | };
|
---|
1203 | R3TestBedCompiler.prototype.overrideProvider = function (token, provider) {
|
---|
1204 | var providerDef;
|
---|
1205 | if (provider.useFactory !== undefined) {
|
---|
1206 | providerDef = {
|
---|
1207 | provide: token,
|
---|
1208 | useFactory: provider.useFactory,
|
---|
1209 | deps: provider.deps || [],
|
---|
1210 | multi: provider.multi
|
---|
1211 | };
|
---|
1212 | }
|
---|
1213 | else if (provider.useValue !== undefined) {
|
---|
1214 | providerDef = { provide: token, useValue: provider.useValue, multi: provider.multi };
|
---|
1215 | }
|
---|
1216 | else {
|
---|
1217 | providerDef = { provide: token };
|
---|
1218 | }
|
---|
1219 | var injectableDef = typeof token !== 'string' ? core.ɵgetInjectableDef(token) : null;
|
---|
1220 | var providedIn = injectableDef === null ? null : core.resolveForwardRef(injectableDef.providedIn);
|
---|
1221 | var overridesBucket = providedIn === 'root' ? this.rootProviderOverrides : this.providerOverrides;
|
---|
1222 | overridesBucket.push(providerDef);
|
---|
1223 | // Keep overrides grouped by token as well for fast lookups using token
|
---|
1224 | this.providerOverridesByToken.set(token, providerDef);
|
---|
1225 | if (injectableDef !== null && providedIn !== null && typeof providedIn !== 'string') {
|
---|
1226 | var existingOverrides = this.providerOverridesByModule.get(providedIn);
|
---|
1227 | if (existingOverrides !== undefined) {
|
---|
1228 | existingOverrides.push(providerDef);
|
---|
1229 | }
|
---|
1230 | else {
|
---|
1231 | this.providerOverridesByModule.set(providedIn, [providerDef]);
|
---|
1232 | }
|
---|
1233 | }
|
---|
1234 | };
|
---|
1235 | R3TestBedCompiler.prototype.overrideTemplateUsingTestingModule = function (type, template) {
|
---|
1236 | var _this = this;
|
---|
1237 | var def = type[core.ɵNG_COMP_DEF];
|
---|
1238 | var hasStyleUrls = function () {
|
---|
1239 | var metadata = _this.resolvers.component.resolve(type);
|
---|
1240 | return !!metadata.styleUrls && metadata.styleUrls.length > 0;
|
---|
1241 | };
|
---|
1242 | var overrideStyleUrls = !!def && !isComponentDefPendingResolution(type) && hasStyleUrls();
|
---|
1243 | // In Ivy, compiling a component does not require knowing the module providing the
|
---|
1244 | // component's scope, so overrideTemplateUsingTestingModule can be implemented purely via
|
---|
1245 | // overrideComponent. Important: overriding template requires full Component re-compilation,
|
---|
1246 | // which may fail in case styleUrls are also present (thus Component is considered as required
|
---|
1247 | // resolution). In order to avoid this, we preemptively set styleUrls to an empty array,
|
---|
1248 | // preserve current styles available on Component def and restore styles back once compilation
|
---|
1249 | // is complete.
|
---|
1250 | var override = overrideStyleUrls ? { template: template, styles: [], styleUrls: [] } : { template: template };
|
---|
1251 | this.overrideComponent(type, { set: override });
|
---|
1252 | if (overrideStyleUrls && def.styles && def.styles.length > 0) {
|
---|
1253 | this.existingComponentStyles.set(type, def.styles);
|
---|
1254 | }
|
---|
1255 | // Set the component's scope to be the testing module.
|
---|
1256 | this.componentToModuleScope.set(type, TestingModuleOverride.OVERRIDE_TEMPLATE);
|
---|
1257 | };
|
---|
1258 | R3TestBedCompiler.prototype.compileComponents = function () {
|
---|
1259 | return __awaiter(this, void 0, void 0, function () {
|
---|
1260 | var needsAsyncResources, resourceLoader_1, resolver;
|
---|
1261 | var _this = this;
|
---|
1262 | return __generator(this, function (_a) {
|
---|
1263 | switch (_a.label) {
|
---|
1264 | case 0:
|
---|
1265 | this.clearComponentResolutionQueue();
|
---|
1266 | needsAsyncResources = this.compileTypesSync();
|
---|
1267 | if (!needsAsyncResources) return [3 /*break*/, 2];
|
---|
1268 | resolver = function (url) {
|
---|
1269 | if (!resourceLoader_1) {
|
---|
1270 | resourceLoader_1 = _this.injector.get(compiler.ResourceLoader);
|
---|
1271 | }
|
---|
1272 | return Promise.resolve(resourceLoader_1.get(url));
|
---|
1273 | };
|
---|
1274 | return [4 /*yield*/, resolveComponentResources(resolver)];
|
---|
1275 | case 1:
|
---|
1276 | _a.sent();
|
---|
1277 | _a.label = 2;
|
---|
1278 | case 2: return [2 /*return*/];
|
---|
1279 | }
|
---|
1280 | });
|
---|
1281 | });
|
---|
1282 | };
|
---|
1283 | R3TestBedCompiler.prototype.finalize = function () {
|
---|
1284 | // One last compile
|
---|
1285 | this.compileTypesSync();
|
---|
1286 | // Create the testing module itself.
|
---|
1287 | this.compileTestModule();
|
---|
1288 | this.applyTransitiveScopes();
|
---|
1289 | this.applyProviderOverrides();
|
---|
1290 | // Patch previously stored `styles` Component values (taken from ɵcmp), in case these
|
---|
1291 | // Components have `styleUrls` fields defined and template override was requested.
|
---|
1292 | this.patchComponentsWithExistingStyles();
|
---|
1293 | // Clear the componentToModuleScope map, so that future compilations don't reset the scope of
|
---|
1294 | // every component.
|
---|
1295 | this.componentToModuleScope.clear();
|
---|
1296 | var parentInjector = this.platform.injector;
|
---|
1297 | this.testModuleRef = new core.ɵRender3NgModuleRef(this.testModuleType, parentInjector);
|
---|
1298 | // ApplicationInitStatus.runInitializers() is marked @internal to core.
|
---|
1299 | // Cast it to any before accessing it.
|
---|
1300 | this.testModuleRef.injector.get(core.ApplicationInitStatus).runInitializers();
|
---|
1301 | // Set locale ID after running app initializers, since locale information might be updated while
|
---|
1302 | // running initializers. This is also consistent with the execution order while bootstrapping an
|
---|
1303 | // app (see `packages/core/src/application_ref.ts` file).
|
---|
1304 | var localeId = this.testModuleRef.injector.get(core.LOCALE_ID, core.ɵDEFAULT_LOCALE_ID);
|
---|
1305 | core.ɵsetLocaleId(localeId);
|
---|
1306 | return this.testModuleRef;
|
---|
1307 | };
|
---|
1308 | /**
|
---|
1309 | * @internal
|
---|
1310 | */
|
---|
1311 | R3TestBedCompiler.prototype._compileNgModuleSync = function (moduleType) {
|
---|
1312 | this.queueTypesFromModulesArray([moduleType]);
|
---|
1313 | this.compileTypesSync();
|
---|
1314 | this.applyProviderOverrides();
|
---|
1315 | this.applyProviderOverridesToModule(moduleType);
|
---|
1316 | this.applyTransitiveScopes();
|
---|
1317 | };
|
---|
1318 | /**
|
---|
1319 | * @internal
|
---|
1320 | */
|
---|
1321 | R3TestBedCompiler.prototype._compileNgModuleAsync = function (moduleType) {
|
---|
1322 | return __awaiter(this, void 0, void 0, function () {
|
---|
1323 | return __generator(this, function (_a) {
|
---|
1324 | switch (_a.label) {
|
---|
1325 | case 0:
|
---|
1326 | this.queueTypesFromModulesArray([moduleType]);
|
---|
1327 | return [4 /*yield*/, this.compileComponents()];
|
---|
1328 | case 1:
|
---|
1329 | _a.sent();
|
---|
1330 | this.applyProviderOverrides();
|
---|
1331 | this.applyProviderOverridesToModule(moduleType);
|
---|
1332 | this.applyTransitiveScopes();
|
---|
1333 | return [2 /*return*/];
|
---|
1334 | }
|
---|
1335 | });
|
---|
1336 | });
|
---|
1337 | };
|
---|
1338 | /**
|
---|
1339 | * @internal
|
---|
1340 | */
|
---|
1341 | R3TestBedCompiler.prototype._getModuleResolver = function () {
|
---|
1342 | return this.resolvers.module;
|
---|
1343 | };
|
---|
1344 | /**
|
---|
1345 | * @internal
|
---|
1346 | */
|
---|
1347 | R3TestBedCompiler.prototype._getComponentFactories = function (moduleType) {
|
---|
1348 | var _this = this;
|
---|
1349 | return maybeUnwrapFn(moduleType.ɵmod.declarations).reduce(function (factories, declaration) {
|
---|
1350 | var componentDef = declaration.ɵcmp;
|
---|
1351 | componentDef && factories.push(new core.ɵRender3ComponentFactory(componentDef, _this.testModuleRef));
|
---|
1352 | return factories;
|
---|
1353 | }, []);
|
---|
1354 | };
|
---|
1355 | R3TestBedCompiler.prototype.compileTypesSync = function () {
|
---|
1356 | var _this = this;
|
---|
1357 | // Compile all queued components, directives, pipes.
|
---|
1358 | var needsAsyncResources = false;
|
---|
1359 | this.pendingComponents.forEach(function (declaration) {
|
---|
1360 | needsAsyncResources = needsAsyncResources || isComponentDefPendingResolution(declaration);
|
---|
1361 | var metadata = _this.resolvers.component.resolve(declaration);
|
---|
1362 | if (metadata === null) {
|
---|
1363 | throw invalidTypeError(declaration.name, 'Component');
|
---|
1364 | }
|
---|
1365 | _this.maybeStoreNgDef(core.ɵNG_COMP_DEF, declaration);
|
---|
1366 | core.ɵcompileComponent(declaration, metadata);
|
---|
1367 | });
|
---|
1368 | this.pendingComponents.clear();
|
---|
1369 | this.pendingDirectives.forEach(function (declaration) {
|
---|
1370 | var metadata = _this.resolvers.directive.resolve(declaration);
|
---|
1371 | if (metadata === null) {
|
---|
1372 | throw invalidTypeError(declaration.name, 'Directive');
|
---|
1373 | }
|
---|
1374 | _this.maybeStoreNgDef(core.ɵNG_DIR_DEF, declaration);
|
---|
1375 | core.ɵcompileDirective(declaration, metadata);
|
---|
1376 | });
|
---|
1377 | this.pendingDirectives.clear();
|
---|
1378 | this.pendingPipes.forEach(function (declaration) {
|
---|
1379 | var metadata = _this.resolvers.pipe.resolve(declaration);
|
---|
1380 | if (metadata === null) {
|
---|
1381 | throw invalidTypeError(declaration.name, 'Pipe');
|
---|
1382 | }
|
---|
1383 | _this.maybeStoreNgDef(core.ɵNG_PIPE_DEF, declaration);
|
---|
1384 | core.ɵcompilePipe(declaration, metadata);
|
---|
1385 | });
|
---|
1386 | this.pendingPipes.clear();
|
---|
1387 | return needsAsyncResources;
|
---|
1388 | };
|
---|
1389 | R3TestBedCompiler.prototype.applyTransitiveScopes = function () {
|
---|
1390 | var _this = this;
|
---|
1391 | if (this.overriddenModules.size > 0) {
|
---|
1392 | // Module overrides (via `TestBed.overrideModule`) might affect scopes that were previously
|
---|
1393 | // calculated and stored in `transitiveCompileScopes`. If module overrides are present,
|
---|
1394 | // collect all affected modules and reset scopes to force their re-calculation.
|
---|
1395 | var testingModuleDef = this.testModuleType[core.ɵNG_MOD_DEF];
|
---|
1396 | var affectedModules = this.collectModulesAffectedByOverrides(testingModuleDef.imports);
|
---|
1397 | if (affectedModules.size > 0) {
|
---|
1398 | affectedModules.forEach(function (moduleType) {
|
---|
1399 | _this.storeFieldOfDefOnType(moduleType, core.ɵNG_MOD_DEF, 'transitiveCompileScopes');
|
---|
1400 | moduleType[core.ɵNG_MOD_DEF].transitiveCompileScopes = null;
|
---|
1401 | });
|
---|
1402 | }
|
---|
1403 | }
|
---|
1404 | var moduleToScope = new Map();
|
---|
1405 | var getScopeOfModule = function (moduleType) {
|
---|
1406 | if (!moduleToScope.has(moduleType)) {
|
---|
1407 | var isTestingModule = isTestingModuleOverride(moduleType);
|
---|
1408 | var realType = isTestingModule ? _this.testModuleType : moduleType;
|
---|
1409 | moduleToScope.set(moduleType, core.ɵtransitiveScopesFor(realType));
|
---|
1410 | }
|
---|
1411 | return moduleToScope.get(moduleType);
|
---|
1412 | };
|
---|
1413 | this.componentToModuleScope.forEach(function (moduleType, componentType) {
|
---|
1414 | var moduleScope = getScopeOfModule(moduleType);
|
---|
1415 | _this.storeFieldOfDefOnType(componentType, core.ɵNG_COMP_DEF, 'directiveDefs');
|
---|
1416 | _this.storeFieldOfDefOnType(componentType, core.ɵNG_COMP_DEF, 'pipeDefs');
|
---|
1417 | // `tView` that is stored on component def contains information about directives and pipes
|
---|
1418 | // that are in the scope of this component. Patching component scope will cause `tView` to be
|
---|
1419 | // changed. Store original `tView` before patching scope, so the `tView` (including scope
|
---|
1420 | // information) is restored back to its previous/original state before running next test.
|
---|
1421 | _this.storeFieldOfDefOnType(componentType, core.ɵNG_COMP_DEF, 'tView');
|
---|
1422 | core.ɵpatchComponentDefWithScope(componentType.ɵcmp, moduleScope);
|
---|
1423 | });
|
---|
1424 | this.componentToModuleScope.clear();
|
---|
1425 | };
|
---|
1426 | R3TestBedCompiler.prototype.applyProviderOverrides = function () {
|
---|
1427 | var _this = this;
|
---|
1428 | var maybeApplyOverrides = function (field) { return function (type) {
|
---|
1429 | var resolver = field === core.ɵNG_COMP_DEF ? _this.resolvers.component : _this.resolvers.directive;
|
---|
1430 | var metadata = resolver.resolve(type);
|
---|
1431 | if (_this.hasProviderOverrides(metadata.providers)) {
|
---|
1432 | _this.patchDefWithProviderOverrides(type, field);
|
---|
1433 | }
|
---|
1434 | }; };
|
---|
1435 | this.seenComponents.forEach(maybeApplyOverrides(core.ɵNG_COMP_DEF));
|
---|
1436 | this.seenDirectives.forEach(maybeApplyOverrides(core.ɵNG_DIR_DEF));
|
---|
1437 | this.seenComponents.clear();
|
---|
1438 | this.seenDirectives.clear();
|
---|
1439 | };
|
---|
1440 | R3TestBedCompiler.prototype.applyProviderOverridesToModule = function (moduleType) {
|
---|
1441 | var e_1, _a, e_2, _b;
|
---|
1442 | if (this.moduleProvidersOverridden.has(moduleType)) {
|
---|
1443 | return;
|
---|
1444 | }
|
---|
1445 | this.moduleProvidersOverridden.add(moduleType);
|
---|
1446 | var injectorDef = moduleType[core.ɵNG_INJ_DEF];
|
---|
1447 | if (this.providerOverridesByToken.size > 0) {
|
---|
1448 | var providers = __spreadArray(__spreadArray([], __read(injectorDef.providers)), __read((this.providerOverridesByModule.get(moduleType) || [])));
|
---|
1449 | if (this.hasProviderOverrides(providers)) {
|
---|
1450 | this.maybeStoreNgDef(core.ɵNG_INJ_DEF, moduleType);
|
---|
1451 | this.storeFieldOfDefOnType(moduleType, core.ɵNG_INJ_DEF, 'providers');
|
---|
1452 | injectorDef.providers = this.getOverriddenProviders(providers);
|
---|
1453 | }
|
---|
1454 | // Apply provider overrides to imported modules recursively
|
---|
1455 | var moduleDef = moduleType[core.ɵNG_MOD_DEF];
|
---|
1456 | var imports = maybeUnwrapFn(moduleDef.imports);
|
---|
1457 | try {
|
---|
1458 | for (var imports_1 = __values(imports), imports_1_1 = imports_1.next(); !imports_1_1.done; imports_1_1 = imports_1.next()) {
|
---|
1459 | var importedModule = imports_1_1.value;
|
---|
1460 | this.applyProviderOverridesToModule(importedModule);
|
---|
1461 | }
|
---|
1462 | }
|
---|
1463 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
---|
1464 | finally {
|
---|
1465 | try {
|
---|
1466 | if (imports_1_1 && !imports_1_1.done && (_a = imports_1.return)) _a.call(imports_1);
|
---|
1467 | }
|
---|
1468 | finally { if (e_1) throw e_1.error; }
|
---|
1469 | }
|
---|
1470 | try {
|
---|
1471 | // Also override the providers on any ModuleWithProviders imports since those don't appear in
|
---|
1472 | // the moduleDef.
|
---|
1473 | for (var _c = __values(flatten(injectorDef.imports)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
---|
1474 | var importedModule = _d.value;
|
---|
1475 | if (isModuleWithProviders(importedModule)) {
|
---|
1476 | this.defCleanupOps.push({
|
---|
1477 | object: importedModule,
|
---|
1478 | fieldName: 'providers',
|
---|
1479 | originalValue: importedModule.providers
|
---|
1480 | });
|
---|
1481 | importedModule.providers = this.getOverriddenProviders(importedModule.providers);
|
---|
1482 | }
|
---|
1483 | }
|
---|
1484 | }
|
---|
1485 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
---|
1486 | finally {
|
---|
1487 | try {
|
---|
1488 | if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
---|
1489 | }
|
---|
1490 | finally { if (e_2) throw e_2.error; }
|
---|
1491 | }
|
---|
1492 | }
|
---|
1493 | };
|
---|
1494 | R3TestBedCompiler.prototype.patchComponentsWithExistingStyles = function () {
|
---|
1495 | this.existingComponentStyles.forEach(function (styles, type) { return type[core.ɵNG_COMP_DEF].styles = styles; });
|
---|
1496 | this.existingComponentStyles.clear();
|
---|
1497 | };
|
---|
1498 | R3TestBedCompiler.prototype.queueTypeArray = function (arr, moduleType) {
|
---|
1499 | var e_3, _a;
|
---|
1500 | try {
|
---|
1501 | for (var arr_1 = __values(arr), arr_1_1 = arr_1.next(); !arr_1_1.done; arr_1_1 = arr_1.next()) {
|
---|
1502 | var value = arr_1_1.value;
|
---|
1503 | if (Array.isArray(value)) {
|
---|
1504 | this.queueTypeArray(value, moduleType);
|
---|
1505 | }
|
---|
1506 | else {
|
---|
1507 | this.queueType(value, moduleType);
|
---|
1508 | }
|
---|
1509 | }
|
---|
1510 | }
|
---|
1511 | catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
---|
1512 | finally {
|
---|
1513 | try {
|
---|
1514 | if (arr_1_1 && !arr_1_1.done && (_a = arr_1.return)) _a.call(arr_1);
|
---|
1515 | }
|
---|
1516 | finally { if (e_3) throw e_3.error; }
|
---|
1517 | }
|
---|
1518 | };
|
---|
1519 | R3TestBedCompiler.prototype.recompileNgModule = function (ngModule, metadata) {
|
---|
1520 | // Cache the initial ngModuleDef as it will be overwritten.
|
---|
1521 | this.maybeStoreNgDef(core.ɵNG_MOD_DEF, ngModule);
|
---|
1522 | this.maybeStoreNgDef(core.ɵNG_INJ_DEF, ngModule);
|
---|
1523 | core.ɵcompileNgModuleDefs(ngModule, metadata);
|
---|
1524 | };
|
---|
1525 | R3TestBedCompiler.prototype.queueType = function (type, moduleType) {
|
---|
1526 | var component = this.resolvers.component.resolve(type);
|
---|
1527 | if (component) {
|
---|
1528 | // Check whether a give Type has respective NG def (ɵcmp) and compile if def is
|
---|
1529 | // missing. That might happen in case a class without any Angular decorators extends another
|
---|
1530 | // class where Component/Directive/Pipe decorator is defined.
|
---|
1531 | if (isComponentDefPendingResolution(type) || !type.hasOwnProperty(core.ɵNG_COMP_DEF)) {
|
---|
1532 | this.pendingComponents.add(type);
|
---|
1533 | }
|
---|
1534 | this.seenComponents.add(type);
|
---|
1535 | // Keep track of the module which declares this component, so later the component's scope
|
---|
1536 | // can be set correctly. If the component has already been recorded here, then one of several
|
---|
1537 | // cases is true:
|
---|
1538 | // * the module containing the component was imported multiple times (common).
|
---|
1539 | // * the component is declared in multiple modules (which is an error).
|
---|
1540 | // * the component was in 'declarations' of the testing module, and also in an imported module
|
---|
1541 | // in which case the module scope will be TestingModuleOverride.DECLARATION.
|
---|
1542 | // * overrideTemplateUsingTestingModule was called for the component in which case the module
|
---|
1543 | // scope will be TestingModuleOverride.OVERRIDE_TEMPLATE.
|
---|
1544 | //
|
---|
1545 | // If the component was previously in the testing module's 'declarations' (meaning the
|
---|
1546 | // current value is TestingModuleOverride.DECLARATION), then `moduleType` is the component's
|
---|
1547 | // real module, which was imported. This pattern is understood to mean that the component
|
---|
1548 | // should use its original scope, but that the testing module should also contain the
|
---|
1549 | // component in its scope.
|
---|
1550 | if (!this.componentToModuleScope.has(type) ||
|
---|
1551 | this.componentToModuleScope.get(type) === TestingModuleOverride.DECLARATION) {
|
---|
1552 | this.componentToModuleScope.set(type, moduleType);
|
---|
1553 | }
|
---|
1554 | return;
|
---|
1555 | }
|
---|
1556 | var directive = this.resolvers.directive.resolve(type);
|
---|
1557 | if (directive) {
|
---|
1558 | if (!type.hasOwnProperty(core.ɵNG_DIR_DEF)) {
|
---|
1559 | this.pendingDirectives.add(type);
|
---|
1560 | }
|
---|
1561 | this.seenDirectives.add(type);
|
---|
1562 | return;
|
---|
1563 | }
|
---|
1564 | var pipe = this.resolvers.pipe.resolve(type);
|
---|
1565 | if (pipe && !type.hasOwnProperty(core.ɵNG_PIPE_DEF)) {
|
---|
1566 | this.pendingPipes.add(type);
|
---|
1567 | return;
|
---|
1568 | }
|
---|
1569 | };
|
---|
1570 | R3TestBedCompiler.prototype.queueTypesFromModulesArray = function (arr) {
|
---|
1571 | var _this = this;
|
---|
1572 | // Because we may encounter the same NgModule while processing the imports and exports of an
|
---|
1573 | // NgModule tree, we cache them in this set so we can skip ones that have already been seen
|
---|
1574 | // encountered. In some test setups, this caching resulted in 10X runtime improvement.
|
---|
1575 | var processedNgModuleDefs = new Set();
|
---|
1576 | var queueTypesFromModulesArrayRecur = function (arr) {
|
---|
1577 | var e_4, _a;
|
---|
1578 | try {
|
---|
1579 | for (var arr_2 = __values(arr), arr_2_1 = arr_2.next(); !arr_2_1.done; arr_2_1 = arr_2.next()) {
|
---|
1580 | var value = arr_2_1.value;
|
---|
1581 | if (Array.isArray(value)) {
|
---|
1582 | queueTypesFromModulesArrayRecur(value);
|
---|
1583 | }
|
---|
1584 | else if (hasNgModuleDef(value)) {
|
---|
1585 | var def = value.ɵmod;
|
---|
1586 | if (processedNgModuleDefs.has(def)) {
|
---|
1587 | continue;
|
---|
1588 | }
|
---|
1589 | processedNgModuleDefs.add(def);
|
---|
1590 | // Look through declarations, imports, and exports, and queue
|
---|
1591 | // everything found there.
|
---|
1592 | _this.queueTypeArray(maybeUnwrapFn(def.declarations), value);
|
---|
1593 | queueTypesFromModulesArrayRecur(maybeUnwrapFn(def.imports));
|
---|
1594 | queueTypesFromModulesArrayRecur(maybeUnwrapFn(def.exports));
|
---|
1595 | }
|
---|
1596 | else if (isModuleWithProviders(value)) {
|
---|
1597 | queueTypesFromModulesArrayRecur([value.ngModule]);
|
---|
1598 | }
|
---|
1599 | }
|
---|
1600 | }
|
---|
1601 | catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
---|
1602 | finally {
|
---|
1603 | try {
|
---|
1604 | if (arr_2_1 && !arr_2_1.done && (_a = arr_2.return)) _a.call(arr_2);
|
---|
1605 | }
|
---|
1606 | finally { if (e_4) throw e_4.error; }
|
---|
1607 | }
|
---|
1608 | };
|
---|
1609 | queueTypesFromModulesArrayRecur(arr);
|
---|
1610 | };
|
---|
1611 | // When module overrides (via `TestBed.overrideModule`) are present, it might affect all modules
|
---|
1612 | // that import (even transitively) an overridden one. For all affected modules we need to
|
---|
1613 | // recalculate their scopes for a given test run and restore original scopes at the end. The goal
|
---|
1614 | // of this function is to collect all affected modules in a set for further processing. Example:
|
---|
1615 | // if we have the following module hierarchy: A -> B -> C (where `->` means `imports`) and module
|
---|
1616 | // `C` is overridden, we consider `A` and `B` as affected, since their scopes might become
|
---|
1617 | // invalidated with the override.
|
---|
1618 | R3TestBedCompiler.prototype.collectModulesAffectedByOverrides = function (arr) {
|
---|
1619 | var _this = this;
|
---|
1620 | var seenModules = new Set();
|
---|
1621 | var affectedModules = new Set();
|
---|
1622 | var calcAffectedModulesRecur = function (arr, path) {
|
---|
1623 | var e_5, _a;
|
---|
1624 | try {
|
---|
1625 | for (var arr_3 = __values(arr), arr_3_1 = arr_3.next(); !arr_3_1.done; arr_3_1 = arr_3.next()) {
|
---|
1626 | var value = arr_3_1.value;
|
---|
1627 | if (Array.isArray(value)) {
|
---|
1628 | // If the value is an array, just flatten it (by invoking this function recursively),
|
---|
1629 | // keeping "path" the same.
|
---|
1630 | calcAffectedModulesRecur(value, path);
|
---|
1631 | }
|
---|
1632 | else if (hasNgModuleDef(value)) {
|
---|
1633 | if (seenModules.has(value)) {
|
---|
1634 | // If we've seen this module before and it's included into "affected modules" list, mark
|
---|
1635 | // the whole path that leads to that module as affected, but do not descend into its
|
---|
1636 | // imports, since we already examined them before.
|
---|
1637 | if (affectedModules.has(value)) {
|
---|
1638 | path.forEach(function (item) { return affectedModules.add(item); });
|
---|
1639 | }
|
---|
1640 | continue;
|
---|
1641 | }
|
---|
1642 | seenModules.add(value);
|
---|
1643 | if (_this.overriddenModules.has(value)) {
|
---|
1644 | path.forEach(function (item) { return affectedModules.add(item); });
|
---|
1645 | }
|
---|
1646 | // Examine module imports recursively to look for overridden modules.
|
---|
1647 | var moduleDef = value[core.ɵNG_MOD_DEF];
|
---|
1648 | calcAffectedModulesRecur(maybeUnwrapFn(moduleDef.imports), path.concat(value));
|
---|
1649 | }
|
---|
1650 | }
|
---|
1651 | }
|
---|
1652 | catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
---|
1653 | finally {
|
---|
1654 | try {
|
---|
1655 | if (arr_3_1 && !arr_3_1.done && (_a = arr_3.return)) _a.call(arr_3);
|
---|
1656 | }
|
---|
1657 | finally { if (e_5) throw e_5.error; }
|
---|
1658 | }
|
---|
1659 | };
|
---|
1660 | calcAffectedModulesRecur(arr, []);
|
---|
1661 | return affectedModules;
|
---|
1662 | };
|
---|
1663 | R3TestBedCompiler.prototype.maybeStoreNgDef = function (prop, type) {
|
---|
1664 | if (!this.initialNgDefs.has(type)) {
|
---|
1665 | var currentDef = Object.getOwnPropertyDescriptor(type, prop);
|
---|
1666 | this.initialNgDefs.set(type, [prop, currentDef]);
|
---|
1667 | }
|
---|
1668 | };
|
---|
1669 | R3TestBedCompiler.prototype.storeFieldOfDefOnType = function (type, defField, fieldName) {
|
---|
1670 | var def = type[defField];
|
---|
1671 | var originalValue = def[fieldName];
|
---|
1672 | this.defCleanupOps.push({ object: def, fieldName: fieldName, originalValue: originalValue });
|
---|
1673 | };
|
---|
1674 | /**
|
---|
1675 | * Clears current components resolution queue, but stores the state of the queue, so we can
|
---|
1676 | * restore it later. Clearing the queue is required before we try to compile components (via
|
---|
1677 | * `TestBed.compileComponents`), so that component defs are in sync with the resolution queue.
|
---|
1678 | */
|
---|
1679 | R3TestBedCompiler.prototype.clearComponentResolutionQueue = function () {
|
---|
1680 | var _this = this;
|
---|
1681 | if (this.originalComponentResolutionQueue === null) {
|
---|
1682 | this.originalComponentResolutionQueue = new Map();
|
---|
1683 | }
|
---|
1684 | clearResolutionOfComponentResourcesQueue().forEach(function (value, key) { return _this.originalComponentResolutionQueue.set(key, value); });
|
---|
1685 | };
|
---|
1686 | /*
|
---|
1687 | * Restores component resolution queue to the previously saved state. This operation is performed
|
---|
1688 | * as a part of restoring the state after completion of the current set of tests (that might
|
---|
1689 | * potentially mutate the state).
|
---|
1690 | */
|
---|
1691 | R3TestBedCompiler.prototype.restoreComponentResolutionQueue = function () {
|
---|
1692 | if (this.originalComponentResolutionQueue !== null) {
|
---|
1693 | restoreComponentResolutionQueue(this.originalComponentResolutionQueue);
|
---|
1694 | this.originalComponentResolutionQueue = null;
|
---|
1695 | }
|
---|
1696 | };
|
---|
1697 | R3TestBedCompiler.prototype.restoreOriginalState = function () {
|
---|
1698 | // Process cleanup ops in reverse order so the field's original value is restored correctly (in
|
---|
1699 | // case there were multiple overrides for the same field).
|
---|
1700 | forEachRight(this.defCleanupOps, function (op) {
|
---|
1701 | op.object[op.fieldName] = op.originalValue;
|
---|
1702 | });
|
---|
1703 | // Restore initial component/directive/pipe defs
|
---|
1704 | this.initialNgDefs.forEach(function (value, type) {
|
---|
1705 | var _a = __read(value, 2), prop = _a[0], descriptor = _a[1];
|
---|
1706 | if (!descriptor) {
|
---|
1707 | // Delete operations are generally undesirable since they have performance implications
|
---|
1708 | // on objects they were applied to. In this particular case, situations where this code
|
---|
1709 | // is invoked should be quite rare to cause any noticeable impact, since it's applied
|
---|
1710 | // only to some test cases (for example when class with no annotations extends some
|
---|
1711 | // @Component) when we need to clear 'ɵcmp' field on a given class to restore
|
---|
1712 | // its original state (before applying overrides and running tests).
|
---|
1713 | delete type[prop];
|
---|
1714 | }
|
---|
1715 | else {
|
---|
1716 | Object.defineProperty(type, prop, descriptor);
|
---|
1717 | }
|
---|
1718 | });
|
---|
1719 | this.initialNgDefs.clear();
|
---|
1720 | this.moduleProvidersOverridden.clear();
|
---|
1721 | this.restoreComponentResolutionQueue();
|
---|
1722 | // Restore the locale ID to the default value, this shouldn't be necessary but we never know
|
---|
1723 | core.ɵsetLocaleId(core.ɵDEFAULT_LOCALE_ID);
|
---|
1724 | };
|
---|
1725 | R3TestBedCompiler.prototype.compileTestModule = function () {
|
---|
1726 | var _this = this;
|
---|
1727 | var RootScopeModule = /** @class */ (function () {
|
---|
1728 | function RootScopeModule() {
|
---|
1729 | }
|
---|
1730 | return RootScopeModule;
|
---|
1731 | }());
|
---|
1732 | core.ɵcompileNgModuleDefs(RootScopeModule, {
|
---|
1733 | providers: __spreadArray([], __read(this.rootProviderOverrides)),
|
---|
1734 | });
|
---|
1735 | var ngZone = new core.NgZone({ enableLongStackTrace: true });
|
---|
1736 | var providers = __spreadArray(__spreadArray([
|
---|
1737 | { provide: core.NgZone, useValue: ngZone },
|
---|
1738 | { provide: core.Compiler, useFactory: function () { return new R3TestCompiler(_this); } }
|
---|
1739 | ], __read(this.providers)), __read(this.providerOverrides));
|
---|
1740 | var imports = [RootScopeModule, this.additionalModuleTypes, this.imports || []];
|
---|
1741 | // clang-format off
|
---|
1742 | core.ɵcompileNgModuleDefs(this.testModuleType, {
|
---|
1743 | declarations: this.declarations,
|
---|
1744 | imports: imports,
|
---|
1745 | schemas: this.schemas,
|
---|
1746 | providers: providers,
|
---|
1747 | }, /* allowDuplicateDeclarationsInRoot */ true);
|
---|
1748 | // clang-format on
|
---|
1749 | this.applyProviderOverridesToModule(this.testModuleType);
|
---|
1750 | };
|
---|
1751 | Object.defineProperty(R3TestBedCompiler.prototype, "injector", {
|
---|
1752 | get: function () {
|
---|
1753 | if (this._injector !== null) {
|
---|
1754 | return this._injector;
|
---|
1755 | }
|
---|
1756 | var providers = [];
|
---|
1757 | var compilerOptions = this.platform.injector.get(core.COMPILER_OPTIONS);
|
---|
1758 | compilerOptions.forEach(function (opts) {
|
---|
1759 | if (opts.providers) {
|
---|
1760 | providers.push(opts.providers);
|
---|
1761 | }
|
---|
1762 | });
|
---|
1763 | if (this.compilerProviders !== null) {
|
---|
1764 | providers.push.apply(providers, __spreadArray([], __read(this.compilerProviders)));
|
---|
1765 | }
|
---|
1766 | // TODO(ocombe): make this work with an Injector directly instead of creating a module for it
|
---|
1767 | var CompilerModule = /** @class */ (function () {
|
---|
1768 | function CompilerModule() {
|
---|
1769 | }
|
---|
1770 | return CompilerModule;
|
---|
1771 | }());
|
---|
1772 | core.ɵcompileNgModuleDefs(CompilerModule, { providers: providers });
|
---|
1773 | var CompilerModuleFactory = new core.ɵNgModuleFactory(CompilerModule);
|
---|
1774 | this._injector = CompilerModuleFactory.create(this.platform.injector).injector;
|
---|
1775 | return this._injector;
|
---|
1776 | },
|
---|
1777 | enumerable: false,
|
---|
1778 | configurable: true
|
---|
1779 | });
|
---|
1780 | // get overrides for a specific provider (if any)
|
---|
1781 | R3TestBedCompiler.prototype.getSingleProviderOverrides = function (provider) {
|
---|
1782 | var token = getProviderToken(provider);
|
---|
1783 | return this.providerOverridesByToken.get(token) || null;
|
---|
1784 | };
|
---|
1785 | R3TestBedCompiler.prototype.getProviderOverrides = function (providers) {
|
---|
1786 | var _this = this;
|
---|
1787 | if (!providers || !providers.length || this.providerOverridesByToken.size === 0)
|
---|
1788 | return [];
|
---|
1789 | // There are two flattening operations here. The inner flatten() operates on the metadata's
|
---|
1790 | // providers and applies a mapping function which retrieves overrides for each incoming
|
---|
1791 | // provider. The outer flatten() then flattens the produced overrides array. If this is not
|
---|
1792 | // done, the array can contain other empty arrays (e.g. `[[], []]`) which leak into the
|
---|
1793 | // providers array and contaminate any error messages that might be generated.
|
---|
1794 | return flatten(flatten(providers, function (provider) { return _this.getSingleProviderOverrides(provider) || []; }));
|
---|
1795 | };
|
---|
1796 | R3TestBedCompiler.prototype.getOverriddenProviders = function (providers) {
|
---|
1797 | var _this = this;
|
---|
1798 | if (!providers || !providers.length || this.providerOverridesByToken.size === 0)
|
---|
1799 | return [];
|
---|
1800 | var flattenedProviders = flatten(providers);
|
---|
1801 | var overrides = this.getProviderOverrides(flattenedProviders);
|
---|
1802 | var overriddenProviders = __spreadArray(__spreadArray([], __read(flattenedProviders)), __read(overrides));
|
---|
1803 | var final = [];
|
---|
1804 | var seenOverriddenProviders = new Set();
|
---|
1805 | // We iterate through the list of providers in reverse order to make sure provider overrides
|
---|
1806 | // take precedence over the values defined in provider list. We also filter out all providers
|
---|
1807 | // that have overrides, keeping overridden values only. This is needed, since presence of a
|
---|
1808 | // provider with `ngOnDestroy` hook will cause this hook to be registered and invoked later.
|
---|
1809 | forEachRight(overriddenProviders, function (provider) {
|
---|
1810 | var token = getProviderToken(provider);
|
---|
1811 | if (_this.providerOverridesByToken.has(token)) {
|
---|
1812 | if (!seenOverriddenProviders.has(token)) {
|
---|
1813 | seenOverriddenProviders.add(token);
|
---|
1814 | // Treat all overridden providers as `{multi: false}` (even if it's a multi-provider) to
|
---|
1815 | // make sure that provided override takes highest precedence and is not combined with
|
---|
1816 | // other instances of the same multi provider.
|
---|
1817 | final.unshift(Object.assign(Object.assign({}, provider), { multi: false }));
|
---|
1818 | }
|
---|
1819 | }
|
---|
1820 | else {
|
---|
1821 | final.unshift(provider);
|
---|
1822 | }
|
---|
1823 | });
|
---|
1824 | return final;
|
---|
1825 | };
|
---|
1826 | R3TestBedCompiler.prototype.hasProviderOverrides = function (providers) {
|
---|
1827 | return this.getProviderOverrides(providers).length > 0;
|
---|
1828 | };
|
---|
1829 | R3TestBedCompiler.prototype.patchDefWithProviderOverrides = function (declaration, field) {
|
---|
1830 | var _this = this;
|
---|
1831 | var def = declaration[field];
|
---|
1832 | if (def && def.providersResolver) {
|
---|
1833 | this.maybeStoreNgDef(field, declaration);
|
---|
1834 | var resolver_1 = def.providersResolver;
|
---|
1835 | var processProvidersFn_1 = function (providers) { return _this.getOverriddenProviders(providers); };
|
---|
1836 | this.storeFieldOfDefOnType(declaration, field, 'providersResolver');
|
---|
1837 | def.providersResolver = function (ngDef) { return resolver_1(ngDef, processProvidersFn_1); };
|
---|
1838 | }
|
---|
1839 | };
|
---|
1840 | return R3TestBedCompiler;
|
---|
1841 | }());
|
---|
1842 | function initResolvers() {
|
---|
1843 | return {
|
---|
1844 | module: new NgModuleResolver(),
|
---|
1845 | component: new ComponentResolver(),
|
---|
1846 | directive: new DirectiveResolver(),
|
---|
1847 | pipe: new PipeResolver()
|
---|
1848 | };
|
---|
1849 | }
|
---|
1850 | function hasNgModuleDef(value) {
|
---|
1851 | return value.hasOwnProperty('ɵmod');
|
---|
1852 | }
|
---|
1853 | function maybeUnwrapFn(maybeFn) {
|
---|
1854 | return maybeFn instanceof Function ? maybeFn() : maybeFn;
|
---|
1855 | }
|
---|
1856 | function flatten(values, mapFn) {
|
---|
1857 | var out = [];
|
---|
1858 | values.forEach(function (value) {
|
---|
1859 | if (Array.isArray(value)) {
|
---|
1860 | out.push.apply(out, __spreadArray([], __read(flatten(value, mapFn))));
|
---|
1861 | }
|
---|
1862 | else {
|
---|
1863 | out.push(mapFn ? mapFn(value) : value);
|
---|
1864 | }
|
---|
1865 | });
|
---|
1866 | return out;
|
---|
1867 | }
|
---|
1868 | function getProviderField(provider, field) {
|
---|
1869 | return provider && typeof provider === 'object' && provider[field];
|
---|
1870 | }
|
---|
1871 | function getProviderToken(provider) {
|
---|
1872 | return getProviderField(provider, 'provide') || provider;
|
---|
1873 | }
|
---|
1874 | function isModuleWithProviders(value) {
|
---|
1875 | return value.hasOwnProperty('ngModule');
|
---|
1876 | }
|
---|
1877 | function forEachRight(values, fn) {
|
---|
1878 | for (var idx = values.length - 1; idx >= 0; idx--) {
|
---|
1879 | fn(values[idx], idx);
|
---|
1880 | }
|
---|
1881 | }
|
---|
1882 | function invalidTypeError(name, expectedType) {
|
---|
1883 | return new Error(name + " class doesn't have @" + expectedType + " decorator or is missing metadata.");
|
---|
1884 | }
|
---|
1885 | var R3TestCompiler = /** @class */ (function () {
|
---|
1886 | function R3TestCompiler(testBed) {
|
---|
1887 | this.testBed = testBed;
|
---|
1888 | }
|
---|
1889 | R3TestCompiler.prototype.compileModuleSync = function (moduleType) {
|
---|
1890 | this.testBed._compileNgModuleSync(moduleType);
|
---|
1891 | return new core.ɵNgModuleFactory(moduleType);
|
---|
1892 | };
|
---|
1893 | R3TestCompiler.prototype.compileModuleAsync = function (moduleType) {
|
---|
1894 | return __awaiter(this, void 0, void 0, function () {
|
---|
1895 | return __generator(this, function (_a) {
|
---|
1896 | switch (_a.label) {
|
---|
1897 | case 0: return [4 /*yield*/, this.testBed._compileNgModuleAsync(moduleType)];
|
---|
1898 | case 1:
|
---|
1899 | _a.sent();
|
---|
1900 | return [2 /*return*/, new core.ɵNgModuleFactory(moduleType)];
|
---|
1901 | }
|
---|
1902 | });
|
---|
1903 | });
|
---|
1904 | };
|
---|
1905 | R3TestCompiler.prototype.compileModuleAndAllComponentsSync = function (moduleType) {
|
---|
1906 | var ngModuleFactory = this.compileModuleSync(moduleType);
|
---|
1907 | var componentFactories = this.testBed._getComponentFactories(moduleType);
|
---|
1908 | return new core.ModuleWithComponentFactories(ngModuleFactory, componentFactories);
|
---|
1909 | };
|
---|
1910 | R3TestCompiler.prototype.compileModuleAndAllComponentsAsync = function (moduleType) {
|
---|
1911 | return __awaiter(this, void 0, void 0, function () {
|
---|
1912 | var ngModuleFactory, componentFactories;
|
---|
1913 | return __generator(this, function (_a) {
|
---|
1914 | switch (_a.label) {
|
---|
1915 | case 0: return [4 /*yield*/, this.compileModuleAsync(moduleType)];
|
---|
1916 | case 1:
|
---|
1917 | ngModuleFactory = _a.sent();
|
---|
1918 | componentFactories = this.testBed._getComponentFactories(moduleType);
|
---|
1919 | return [2 /*return*/, new core.ModuleWithComponentFactories(ngModuleFactory, componentFactories)];
|
---|
1920 | }
|
---|
1921 | });
|
---|
1922 | });
|
---|
1923 | };
|
---|
1924 | R3TestCompiler.prototype.clearCache = function () { };
|
---|
1925 | R3TestCompiler.prototype.clearCacheFor = function (type) { };
|
---|
1926 | R3TestCompiler.prototype.getModuleId = function (moduleType) {
|
---|
1927 | var meta = this.testBed._getModuleResolver().resolve(moduleType);
|
---|
1928 | return meta && meta.id || undefined;
|
---|
1929 | };
|
---|
1930 | return R3TestCompiler;
|
---|
1931 | }());
|
---|
1932 |
|
---|
1933 | /**
|
---|
1934 | * @license
|
---|
1935 | * Copyright Google LLC All Rights Reserved.
|
---|
1936 | *
|
---|
1937 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1938 | * found in the LICENSE file at https://angular.io/license
|
---|
1939 | */
|
---|
1940 | /**
|
---|
1941 | * Whether test modules should be torn down by default.
|
---|
1942 | * Currently disabled for backwards-compatibility reasons.
|
---|
1943 | */
|
---|
1944 | var TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT = false;
|
---|
1945 | /**
|
---|
1946 | * An abstract class for inserting the root test component element in a platform independent way.
|
---|
1947 | *
|
---|
1948 | * @publicApi
|
---|
1949 | */
|
---|
1950 | var TestComponentRenderer = /** @class */ (function () {
|
---|
1951 | function TestComponentRenderer() {
|
---|
1952 | }
|
---|
1953 | TestComponentRenderer.prototype.insertRootElement = function (rootElementId) { };
|
---|
1954 | TestComponentRenderer.prototype.removeAllRootElements = function () { };
|
---|
1955 | return TestComponentRenderer;
|
---|
1956 | }());
|
---|
1957 | /**
|
---|
1958 | * @publicApi
|
---|
1959 | */
|
---|
1960 | var ComponentFixtureAutoDetect = new core.InjectionToken('ComponentFixtureAutoDetect');
|
---|
1961 | /**
|
---|
1962 | * @publicApi
|
---|
1963 | */
|
---|
1964 | var ComponentFixtureNoNgZone = new core.InjectionToken('ComponentFixtureNoNgZone');
|
---|
1965 |
|
---|
1966 | /**
|
---|
1967 | * @license
|
---|
1968 | * Copyright Google LLC All Rights Reserved.
|
---|
1969 | *
|
---|
1970 | * Use of this source code is governed by an MIT-style license that can be
|
---|
1971 | * found in the LICENSE file at https://angular.io/license
|
---|
1972 | */
|
---|
1973 | var _nextRootElementId = 0;
|
---|
1974 | /**
|
---|
1975 | * @description
|
---|
1976 | * Configures and initializes environment for unit testing and provides methods for
|
---|
1977 | * creating components and services in unit tests.
|
---|
1978 | *
|
---|
1979 | * TestBed is the primary api for writing unit tests for Angular applications and libraries.
|
---|
1980 | *
|
---|
1981 | * Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
|
---|
1982 | * according to the compiler used.
|
---|
1983 | */
|
---|
1984 | var TestBedRender3 = /** @class */ (function () {
|
---|
1985 | function TestBedRender3() {
|
---|
1986 | // Properties
|
---|
1987 | this.platform = null;
|
---|
1988 | this.ngModule = null;
|
---|
1989 | this._compiler = null;
|
---|
1990 | this._testModuleRef = null;
|
---|
1991 | this._activeFixtures = [];
|
---|
1992 | this._globalCompilationChecked = false;
|
---|
1993 | }
|
---|
1994 | /**
|
---|
1995 | * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
---|
1996 | * angular module. These are common to every test in the suite.
|
---|
1997 | *
|
---|
1998 | * This may only be called once, to set up the common providers for the current test
|
---|
1999 | * suite on the current platform. If you absolutely need to change the providers,
|
---|
2000 | * first use `resetTestEnvironment`.
|
---|
2001 | *
|
---|
2002 | * Test modules and platforms for individual platforms are available from
|
---|
2003 | * '@angular/<platform_name>/testing'.
|
---|
2004 | *
|
---|
2005 | * @publicApi
|
---|
2006 | */
|
---|
2007 | TestBedRender3.initTestEnvironment = function (ngModule, platform, summariesOrOptions) {
|
---|
2008 | var testBed = _getTestBedRender3();
|
---|
2009 | testBed.initTestEnvironment(ngModule, platform, summariesOrOptions);
|
---|
2010 | return testBed;
|
---|
2011 | };
|
---|
2012 | /**
|
---|
2013 | * Reset the providers for the test injector.
|
---|
2014 | *
|
---|
2015 | * @publicApi
|
---|
2016 | */
|
---|
2017 | TestBedRender3.resetTestEnvironment = function () {
|
---|
2018 | _getTestBedRender3().resetTestEnvironment();
|
---|
2019 | };
|
---|
2020 | TestBedRender3.configureCompiler = function (config) {
|
---|
2021 | _getTestBedRender3().configureCompiler(config);
|
---|
2022 | return TestBedRender3;
|
---|
2023 | };
|
---|
2024 | /**
|
---|
2025 | * Allows overriding default providers, directives, pipes, modules of the test injector,
|
---|
2026 | * which are defined in test_injector.js
|
---|
2027 | */
|
---|
2028 | TestBedRender3.configureTestingModule = function (moduleDef) {
|
---|
2029 | _getTestBedRender3().configureTestingModule(moduleDef);
|
---|
2030 | return TestBedRender3;
|
---|
2031 | };
|
---|
2032 | /**
|
---|
2033 | * Compile components with a `templateUrl` for the test's NgModule.
|
---|
2034 | * It is necessary to call this function
|
---|
2035 | * as fetching urls is asynchronous.
|
---|
2036 | */
|
---|
2037 | TestBedRender3.compileComponents = function () {
|
---|
2038 | return _getTestBedRender3().compileComponents();
|
---|
2039 | };
|
---|
2040 | TestBedRender3.overrideModule = function (ngModule, override) {
|
---|
2041 | _getTestBedRender3().overrideModule(ngModule, override);
|
---|
2042 | return TestBedRender3;
|
---|
2043 | };
|
---|
2044 | TestBedRender3.overrideComponent = function (component, override) {
|
---|
2045 | _getTestBedRender3().overrideComponent(component, override);
|
---|
2046 | return TestBedRender3;
|
---|
2047 | };
|
---|
2048 | TestBedRender3.overrideDirective = function (directive, override) {
|
---|
2049 | _getTestBedRender3().overrideDirective(directive, override);
|
---|
2050 | return TestBedRender3;
|
---|
2051 | };
|
---|
2052 | TestBedRender3.overridePipe = function (pipe, override) {
|
---|
2053 | _getTestBedRender3().overridePipe(pipe, override);
|
---|
2054 | return TestBedRender3;
|
---|
2055 | };
|
---|
2056 | TestBedRender3.overrideTemplate = function (component, template) {
|
---|
2057 | _getTestBedRender3().overrideComponent(component, { set: { template: template, templateUrl: null } });
|
---|
2058 | return TestBedRender3;
|
---|
2059 | };
|
---|
2060 | /**
|
---|
2061 | * Overrides the template of the given component, compiling the template
|
---|
2062 | * in the context of the TestingModule.
|
---|
2063 | *
|
---|
2064 | * Note: This works for JIT and AOTed components as well.
|
---|
2065 | */
|
---|
2066 | TestBedRender3.overrideTemplateUsingTestingModule = function (component, template) {
|
---|
2067 | _getTestBedRender3().overrideTemplateUsingTestingModule(component, template);
|
---|
2068 | return TestBedRender3;
|
---|
2069 | };
|
---|
2070 | TestBedRender3.overrideProvider = function (token, provider) {
|
---|
2071 | _getTestBedRender3().overrideProvider(token, provider);
|
---|
2072 | return TestBedRender3;
|
---|
2073 | };
|
---|
2074 | TestBedRender3.inject = function (token, notFoundValue, flags) {
|
---|
2075 | return _getTestBedRender3().inject(token, notFoundValue, flags);
|
---|
2076 | };
|
---|
2077 | /** @deprecated from v9.0.0 use TestBed.inject */
|
---|
2078 | TestBedRender3.get = function (token, notFoundValue, flags) {
|
---|
2079 | if (notFoundValue === void 0) { notFoundValue = core.Injector.THROW_IF_NOT_FOUND; }
|
---|
2080 | if (flags === void 0) { flags = core.InjectFlags.Default; }
|
---|
2081 | return _getTestBedRender3().inject(token, notFoundValue, flags);
|
---|
2082 | };
|
---|
2083 | TestBedRender3.createComponent = function (component) {
|
---|
2084 | return _getTestBedRender3().createComponent(component);
|
---|
2085 | };
|
---|
2086 | TestBedRender3.resetTestingModule = function () {
|
---|
2087 | _getTestBedRender3().resetTestingModule();
|
---|
2088 | return TestBedRender3;
|
---|
2089 | };
|
---|
2090 | TestBedRender3.shouldTearDownTestingModule = function () {
|
---|
2091 | return _getTestBedRender3().shouldTearDownTestingModule();
|
---|
2092 | };
|
---|
2093 | TestBedRender3.tearDownTestingModule = function () {
|
---|
2094 | _getTestBedRender3().tearDownTestingModule();
|
---|
2095 | };
|
---|
2096 | /**
|
---|
2097 | * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
---|
2098 | * angular module. These are common to every test in the suite.
|
---|
2099 | *
|
---|
2100 | * This may only be called once, to set up the common providers for the current test
|
---|
2101 | * suite on the current platform. If you absolutely need to change the providers,
|
---|
2102 | * first use `resetTestEnvironment`.
|
---|
2103 | *
|
---|
2104 | * Test modules and platforms for individual platforms are available from
|
---|
2105 | * '@angular/<platform_name>/testing'.
|
---|
2106 | *
|
---|
2107 | * @publicApi
|
---|
2108 | */
|
---|
2109 | TestBedRender3.prototype.initTestEnvironment = function (ngModule, platform, summariesOrOptions) {
|
---|
2110 | if (this.platform || this.ngModule) {
|
---|
2111 | throw new Error('Cannot set base providers because it has already been called');
|
---|
2112 | }
|
---|
2113 | // If `summariesOrOptions` is a function, it means that it's
|
---|
2114 | // an AOT summaries factory which Ivy doesn't support.
|
---|
2115 | TestBedRender3._environmentTeardownOptions =
|
---|
2116 | typeof summariesOrOptions === 'function' ? undefined : summariesOrOptions === null || summariesOrOptions === void 0 ? void 0 : summariesOrOptions.teardown;
|
---|
2117 | this.platform = platform;
|
---|
2118 | this.ngModule = ngModule;
|
---|
2119 | this._compiler = new R3TestBedCompiler(this.platform, this.ngModule);
|
---|
2120 | };
|
---|
2121 | /**
|
---|
2122 | * Reset the providers for the test injector.
|
---|
2123 | *
|
---|
2124 | * @publicApi
|
---|
2125 | */
|
---|
2126 | TestBedRender3.prototype.resetTestEnvironment = function () {
|
---|
2127 | this.resetTestingModule();
|
---|
2128 | this._compiler = null;
|
---|
2129 | this.platform = null;
|
---|
2130 | this.ngModule = null;
|
---|
2131 | TestBedRender3._environmentTeardownOptions = undefined;
|
---|
2132 | };
|
---|
2133 | TestBedRender3.prototype.resetTestingModule = function () {
|
---|
2134 | this.checkGlobalCompilationFinished();
|
---|
2135 | core.ɵresetCompiledComponents();
|
---|
2136 | if (this._compiler !== null) {
|
---|
2137 | this.compiler.restoreOriginalState();
|
---|
2138 | }
|
---|
2139 | this._compiler = new R3TestBedCompiler(this.platform, this.ngModule);
|
---|
2140 | // We have to chain a couple of try/finally blocks, because each step can
|
---|
2141 | // throw errors and we don't want it to interrupt the next step and we also
|
---|
2142 | // want an error to be thrown at the end.
|
---|
2143 | try {
|
---|
2144 | this.destroyActiveFixtures();
|
---|
2145 | }
|
---|
2146 | finally {
|
---|
2147 | try {
|
---|
2148 | if (this.shouldTearDownTestingModule()) {
|
---|
2149 | this.tearDownTestingModule();
|
---|
2150 | }
|
---|
2151 | }
|
---|
2152 | finally {
|
---|
2153 | this._testModuleRef = null;
|
---|
2154 | this._instanceTeardownOptions = undefined;
|
---|
2155 | }
|
---|
2156 | }
|
---|
2157 | };
|
---|
2158 | TestBedRender3.prototype.configureCompiler = function (config) {
|
---|
2159 | if (config.useJit != null) {
|
---|
2160 | throw new Error('the Render3 compiler JiT mode is not configurable !');
|
---|
2161 | }
|
---|
2162 | if (config.providers !== undefined) {
|
---|
2163 | this.compiler.setCompilerProviders(config.providers);
|
---|
2164 | }
|
---|
2165 | };
|
---|
2166 | TestBedRender3.prototype.configureTestingModule = function (moduleDef) {
|
---|
2167 | this.assertNotInstantiated('R3TestBed.configureTestingModule', 'configure the test module');
|
---|
2168 | // Always re-assign the teardown options, even if they're undefined.
|
---|
2169 | // This ensures that we don't carry the options between tests.
|
---|
2170 | this._instanceTeardownOptions = moduleDef.teardown;
|
---|
2171 | this.compiler.configureTestingModule(moduleDef);
|
---|
2172 | };
|
---|
2173 | TestBedRender3.prototype.compileComponents = function () {
|
---|
2174 | return this.compiler.compileComponents();
|
---|
2175 | };
|
---|
2176 | TestBedRender3.prototype.inject = function (token, notFoundValue, flags) {
|
---|
2177 | if (token === TestBedRender3) {
|
---|
2178 | return this;
|
---|
2179 | }
|
---|
2180 | var UNDEFINED = {};
|
---|
2181 | var result = this.testModuleRef.injector.get(token, UNDEFINED, flags);
|
---|
2182 | return result === UNDEFINED ? this.compiler.injector.get(token, notFoundValue, flags) :
|
---|
2183 | result;
|
---|
2184 | };
|
---|
2185 | /** @deprecated from v9.0.0 use TestBed.inject */
|
---|
2186 | TestBedRender3.prototype.get = function (token, notFoundValue, flags) {
|
---|
2187 | if (notFoundValue === void 0) { notFoundValue = core.Injector.THROW_IF_NOT_FOUND; }
|
---|
2188 | if (flags === void 0) { flags = core.InjectFlags.Default; }
|
---|
2189 | return this.inject(token, notFoundValue, flags);
|
---|
2190 | };
|
---|
2191 | TestBedRender3.prototype.execute = function (tokens, fn, context) {
|
---|
2192 | var _this = this;
|
---|
2193 | var params = tokens.map(function (t) { return _this.inject(t); });
|
---|
2194 | return fn.apply(context, params);
|
---|
2195 | };
|
---|
2196 | TestBedRender3.prototype.overrideModule = function (ngModule, override) {
|
---|
2197 | this.assertNotInstantiated('overrideModule', 'override module metadata');
|
---|
2198 | this.compiler.overrideModule(ngModule, override);
|
---|
2199 | };
|
---|
2200 | TestBedRender3.prototype.overrideComponent = function (component, override) {
|
---|
2201 | this.assertNotInstantiated('overrideComponent', 'override component metadata');
|
---|
2202 | this.compiler.overrideComponent(component, override);
|
---|
2203 | };
|
---|
2204 | TestBedRender3.prototype.overrideTemplateUsingTestingModule = function (component, template) {
|
---|
2205 | this.assertNotInstantiated('R3TestBed.overrideTemplateUsingTestingModule', 'Cannot override template when the test module has already been instantiated');
|
---|
2206 | this.compiler.overrideTemplateUsingTestingModule(component, template);
|
---|
2207 | };
|
---|
2208 | TestBedRender3.prototype.overrideDirective = function (directive, override) {
|
---|
2209 | this.assertNotInstantiated('overrideDirective', 'override directive metadata');
|
---|
2210 | this.compiler.overrideDirective(directive, override);
|
---|
2211 | };
|
---|
2212 | TestBedRender3.prototype.overridePipe = function (pipe, override) {
|
---|
2213 | this.assertNotInstantiated('overridePipe', 'override pipe metadata');
|
---|
2214 | this.compiler.overridePipe(pipe, override);
|
---|
2215 | };
|
---|
2216 | /**
|
---|
2217 | * Overwrites all providers for the given token with the given provider definition.
|
---|
2218 | */
|
---|
2219 | TestBedRender3.prototype.overrideProvider = function (token, provider) {
|
---|
2220 | this.assertNotInstantiated('overrideProvider', 'override provider');
|
---|
2221 | this.compiler.overrideProvider(token, provider);
|
---|
2222 | };
|
---|
2223 | TestBedRender3.prototype.createComponent = function (type) {
|
---|
2224 | var _this = this;
|
---|
2225 | var testComponentRenderer = this.inject(TestComponentRenderer);
|
---|
2226 | var rootElId = "root" + _nextRootElementId++;
|
---|
2227 | testComponentRenderer.insertRootElement(rootElId);
|
---|
2228 | var componentDef = type.ɵcmp;
|
---|
2229 | if (!componentDef) {
|
---|
2230 | throw new Error("It looks like '" + core.ɵstringify(type) + "' has not been IVY compiled - it has no '\u0275cmp' field");
|
---|
2231 | }
|
---|
2232 | // TODO: Don't cast as `InjectionToken<boolean>`, proper type is boolean[]
|
---|
2233 | var noNgZone = this.inject(ComponentFixtureNoNgZone, false);
|
---|
2234 | // TODO: Don't cast as `InjectionToken<boolean>`, proper type is boolean[]
|
---|
2235 | var autoDetect = this.inject(ComponentFixtureAutoDetect, false);
|
---|
2236 | var ngZone = noNgZone ? null : this.inject(core.NgZone, null);
|
---|
2237 | var componentFactory = new core.ɵRender3ComponentFactory(componentDef);
|
---|
2238 | var initComponent = function () {
|
---|
2239 | var componentRef = componentFactory.create(core.Injector.NULL, [], "#" + rootElId, _this.testModuleRef);
|
---|
2240 | return new ComponentFixture(componentRef, ngZone, autoDetect);
|
---|
2241 | };
|
---|
2242 | var fixture = ngZone ? ngZone.run(initComponent) : initComponent();
|
---|
2243 | this._activeFixtures.push(fixture);
|
---|
2244 | return fixture;
|
---|
2245 | };
|
---|
2246 | Object.defineProperty(TestBedRender3.prototype, "compiler", {
|
---|
2247 | /**
|
---|
2248 | * @internal strip this from published d.ts files due to
|
---|
2249 | * https://github.com/microsoft/TypeScript/issues/36216
|
---|
2250 | */
|
---|
2251 | get: function () {
|
---|
2252 | if (this._compiler === null) {
|
---|
2253 | throw new Error("Need to call TestBed.initTestEnvironment() first");
|
---|
2254 | }
|
---|
2255 | return this._compiler;
|
---|
2256 | },
|
---|
2257 | enumerable: false,
|
---|
2258 | configurable: true
|
---|
2259 | });
|
---|
2260 | Object.defineProperty(TestBedRender3.prototype, "testModuleRef", {
|
---|
2261 | /**
|
---|
2262 | * @internal strip this from published d.ts files due to
|
---|
2263 | * https://github.com/microsoft/TypeScript/issues/36216
|
---|
2264 | */
|
---|
2265 | get: function () {
|
---|
2266 | if (this._testModuleRef === null) {
|
---|
2267 | this._testModuleRef = this.compiler.finalize();
|
---|
2268 | }
|
---|
2269 | return this._testModuleRef;
|
---|
2270 | },
|
---|
2271 | enumerable: false,
|
---|
2272 | configurable: true
|
---|
2273 | });
|
---|
2274 | TestBedRender3.prototype.assertNotInstantiated = function (methodName, methodDescription) {
|
---|
2275 | if (this._testModuleRef !== null) {
|
---|
2276 | throw new Error("Cannot " + methodDescription + " when the test module has already been instantiated. " +
|
---|
2277 | ("Make sure you are not using `inject` before `" + methodName + "`."));
|
---|
2278 | }
|
---|
2279 | };
|
---|
2280 | /**
|
---|
2281 | * Check whether the module scoping queue should be flushed, and flush it if needed.
|
---|
2282 | *
|
---|
2283 | * When the TestBed is reset, it clears the JIT module compilation queue, cancelling any
|
---|
2284 | * in-progress module compilation. This creates a potential hazard - the very first time the
|
---|
2285 | * TestBed is initialized (or if it's reset without being initialized), there may be pending
|
---|
2286 | * compilations of modules declared in global scope. These compilations should be finished.
|
---|
2287 | *
|
---|
2288 | * To ensure that globally declared modules have their components scoped properly, this function
|
---|
2289 | * is called whenever TestBed is initialized or reset. The _first_ time that this happens, prior
|
---|
2290 | * to any other operations, the scoping queue is flushed.
|
---|
2291 | */
|
---|
2292 | TestBedRender3.prototype.checkGlobalCompilationFinished = function () {
|
---|
2293 | // Checking _testNgModuleRef is null should not be necessary, but is left in as an additional
|
---|
2294 | // guard that compilations queued in tests (after instantiation) are never flushed accidentally.
|
---|
2295 | if (!this._globalCompilationChecked && this._testModuleRef === null) {
|
---|
2296 | core.ɵflushModuleScopingQueueAsMuchAsPossible();
|
---|
2297 | }
|
---|
2298 | this._globalCompilationChecked = true;
|
---|
2299 | };
|
---|
2300 | TestBedRender3.prototype.destroyActiveFixtures = function () {
|
---|
2301 | var errorCount = 0;
|
---|
2302 | this._activeFixtures.forEach(function (fixture) {
|
---|
2303 | try {
|
---|
2304 | fixture.destroy();
|
---|
2305 | }
|
---|
2306 | catch (e) {
|
---|
2307 | errorCount++;
|
---|
2308 | console.error('Error during cleanup of component', {
|
---|
2309 | component: fixture.componentInstance,
|
---|
2310 | stacktrace: e,
|
---|
2311 | });
|
---|
2312 | }
|
---|
2313 | });
|
---|
2314 | this._activeFixtures = [];
|
---|
2315 | if (errorCount > 0 && this.shouldRethrowTeardownErrors()) {
|
---|
2316 | throw Error(errorCount + " " + (errorCount === 1 ? 'component' : 'components') + " " +
|
---|
2317 | "threw errors during cleanup");
|
---|
2318 | }
|
---|
2319 | };
|
---|
2320 | TestBedRender3.prototype.shouldRethrowTeardownErrors = function () {
|
---|
2321 | var _a, _b;
|
---|
2322 | var instanceOptions = this._instanceTeardownOptions;
|
---|
2323 | var environmentOptions = TestBedRender3._environmentTeardownOptions;
|
---|
2324 | // If the new teardown behavior hasn't been configured, preserve the old behavior.
|
---|
2325 | if (!instanceOptions && !environmentOptions) {
|
---|
2326 | return false;
|
---|
2327 | }
|
---|
2328 | // Otherwise use the configured behavior or default to rethrowing.
|
---|
2329 | return (_b = (_a = instanceOptions === null || instanceOptions === void 0 ? void 0 : instanceOptions.rethrowErrors) !== null && _a !== void 0 ? _a : environmentOptions === null || environmentOptions === void 0 ? void 0 : environmentOptions.rethrowErrors) !== null && _b !== void 0 ? _b : true;
|
---|
2330 | };
|
---|
2331 | TestBedRender3.prototype.shouldTearDownTestingModule = function () {
|
---|
2332 | var _a, _b, _c, _d;
|
---|
2333 | return (_d = (_b = (_a = this._instanceTeardownOptions) === null || _a === void 0 ? void 0 : _a.destroyAfterEach) !== null && _b !== void 0 ? _b : (_c = TestBedRender3._environmentTeardownOptions) === null || _c === void 0 ? void 0 : _c.destroyAfterEach) !== null && _d !== void 0 ? _d : TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT;
|
---|
2334 | };
|
---|
2335 | TestBedRender3.prototype.tearDownTestingModule = function () {
|
---|
2336 | var _a;
|
---|
2337 | // If the module ref has already been destroyed, we won't be able to get a test renderer.
|
---|
2338 | if (this._testModuleRef === null) {
|
---|
2339 | return;
|
---|
2340 | }
|
---|
2341 | // Resolve the renderer ahead of time, because we want to remove the root elements as the very
|
---|
2342 | // last step, but the injector will be destroyed as a part of the module ref destruction.
|
---|
2343 | var testRenderer = this.inject(TestComponentRenderer);
|
---|
2344 | try {
|
---|
2345 | this._testModuleRef.destroy();
|
---|
2346 | }
|
---|
2347 | catch (e) {
|
---|
2348 | if (this.shouldRethrowTeardownErrors()) {
|
---|
2349 | throw e;
|
---|
2350 | }
|
---|
2351 | else {
|
---|
2352 | console.error('Error during cleanup of a testing module', {
|
---|
2353 | component: this._testModuleRef.instance,
|
---|
2354 | stacktrace: e,
|
---|
2355 | });
|
---|
2356 | }
|
---|
2357 | }
|
---|
2358 | finally {
|
---|
2359 | (_a = testRenderer.removeAllRootElements) === null || _a === void 0 ? void 0 : _a.call(testRenderer);
|
---|
2360 | }
|
---|
2361 | };
|
---|
2362 | return TestBedRender3;
|
---|
2363 | }());
|
---|
2364 | var testBed;
|
---|
2365 | function _getTestBedRender3() {
|
---|
2366 | return testBed = testBed || new TestBedRender3();
|
---|
2367 | }
|
---|
2368 |
|
---|
2369 | function unimplemented() {
|
---|
2370 | throw Error('unimplemented');
|
---|
2371 | }
|
---|
2372 | /**
|
---|
2373 | * Special interface to the compiler only used by testing
|
---|
2374 | *
|
---|
2375 | * @publicApi
|
---|
2376 | */
|
---|
2377 | var TestingCompiler = /** @class */ (function (_super) {
|
---|
2378 | __extends(TestingCompiler, _super);
|
---|
2379 | function TestingCompiler() {
|
---|
2380 | return _super !== null && _super.apply(this, arguments) || this;
|
---|
2381 | }
|
---|
2382 | Object.defineProperty(TestingCompiler.prototype, "injector", {
|
---|
2383 | get: function () {
|
---|
2384 | throw unimplemented();
|
---|
2385 | },
|
---|
2386 | enumerable: false,
|
---|
2387 | configurable: true
|
---|
2388 | });
|
---|
2389 | TestingCompiler.prototype.overrideModule = function (module, overrides) {
|
---|
2390 | throw unimplemented();
|
---|
2391 | };
|
---|
2392 | TestingCompiler.prototype.overrideDirective = function (directive, overrides) {
|
---|
2393 | throw unimplemented();
|
---|
2394 | };
|
---|
2395 | TestingCompiler.prototype.overrideComponent = function (component, overrides) {
|
---|
2396 | throw unimplemented();
|
---|
2397 | };
|
---|
2398 | TestingCompiler.prototype.overridePipe = function (directive, overrides) {
|
---|
2399 | throw unimplemented();
|
---|
2400 | };
|
---|
2401 | /**
|
---|
2402 | * Allows to pass the compile summary from AOT compilation to the JIT compiler,
|
---|
2403 | * so that it can use the code generated by AOT.
|
---|
2404 | */
|
---|
2405 | TestingCompiler.prototype.loadAotSummaries = function (summaries) {
|
---|
2406 | throw unimplemented();
|
---|
2407 | };
|
---|
2408 | /**
|
---|
2409 | * Gets the component factory for the given component.
|
---|
2410 | * This assumes that the component has been compiled before calling this call using
|
---|
2411 | * `compileModuleAndAllComponents*`.
|
---|
2412 | */
|
---|
2413 | TestingCompiler.prototype.getComponentFactory = function (component) {
|
---|
2414 | throw unimplemented();
|
---|
2415 | };
|
---|
2416 | /**
|
---|
2417 | * Returns the component type that is stored in the given error.
|
---|
2418 | * This can be used for errors created by compileModule...
|
---|
2419 | */
|
---|
2420 | TestingCompiler.prototype.getComponentFromError = function (error) {
|
---|
2421 | throw unimplemented();
|
---|
2422 | };
|
---|
2423 | return TestingCompiler;
|
---|
2424 | }(core.Compiler));
|
---|
2425 | TestingCompiler.decorators = [
|
---|
2426 | { type: core.Injectable }
|
---|
2427 | ];
|
---|
2428 | /**
|
---|
2429 | * A factory for creating a Compiler
|
---|
2430 | *
|
---|
2431 | * @publicApi
|
---|
2432 | */
|
---|
2433 | var TestingCompilerFactory = /** @class */ (function () {
|
---|
2434 | function TestingCompilerFactory() {
|
---|
2435 | }
|
---|
2436 | return TestingCompilerFactory;
|
---|
2437 | }());
|
---|
2438 |
|
---|
2439 | var _nextRootElementId$1 = 0;
|
---|
2440 | /**
|
---|
2441 | * @description
|
---|
2442 | * Configures and initializes environment for unit testing and provides methods for
|
---|
2443 | * creating components and services in unit tests.
|
---|
2444 | *
|
---|
2445 | * `TestBed` is the primary api for writing unit tests for Angular applications and libraries.
|
---|
2446 | *
|
---|
2447 | * Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
|
---|
2448 | * according to the compiler used.
|
---|
2449 | */
|
---|
2450 | var TestBedViewEngine = /** @class */ (function () {
|
---|
2451 | function TestBedViewEngine() {
|
---|
2452 | this._instantiated = false;
|
---|
2453 | this._compiler = null;
|
---|
2454 | this._moduleRef = null;
|
---|
2455 | this._moduleFactory = null;
|
---|
2456 | this._pendingModuleFactory = null;
|
---|
2457 | this._compilerOptions = [];
|
---|
2458 | this._moduleOverrides = [];
|
---|
2459 | this._componentOverrides = [];
|
---|
2460 | this._directiveOverrides = [];
|
---|
2461 | this._pipeOverrides = [];
|
---|
2462 | this._providers = [];
|
---|
2463 | this._declarations = [];
|
---|
2464 | this._imports = [];
|
---|
2465 | this._schemas = [];
|
---|
2466 | this._activeFixtures = [];
|
---|
2467 | this._testEnvAotSummaries = function () { return []; };
|
---|
2468 | this._aotSummaries = [];
|
---|
2469 | this._templateOverrides = [];
|
---|
2470 | this._isRoot = true;
|
---|
2471 | this._rootProviderOverrides = [];
|
---|
2472 | this.platform = null;
|
---|
2473 | this.ngModule = null;
|
---|
2474 | }
|
---|
2475 | /**
|
---|
2476 | * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
---|
2477 | * angular module. These are common to every test in the suite.
|
---|
2478 | *
|
---|
2479 | * This may only be called once, to set up the common providers for the current test
|
---|
2480 | * suite on the current platform. If you absolutely need to change the providers,
|
---|
2481 | * first use `resetTestEnvironment`.
|
---|
2482 | *
|
---|
2483 | * Test modules and platforms for individual platforms are available from
|
---|
2484 | * '@angular/<platform_name>/testing'.
|
---|
2485 | */
|
---|
2486 | TestBedViewEngine.initTestEnvironment = function (ngModule, platform, summariesOrOptions) {
|
---|
2487 | var testBed = _getTestBedViewEngine();
|
---|
2488 | testBed.initTestEnvironment(ngModule, platform, summariesOrOptions);
|
---|
2489 | return testBed;
|
---|
2490 | };
|
---|
2491 | /**
|
---|
2492 | * Reset the providers for the test injector.
|
---|
2493 | */
|
---|
2494 | TestBedViewEngine.resetTestEnvironment = function () {
|
---|
2495 | _getTestBedViewEngine().resetTestEnvironment();
|
---|
2496 | };
|
---|
2497 | TestBedViewEngine.resetTestingModule = function () {
|
---|
2498 | _getTestBedViewEngine().resetTestingModule();
|
---|
2499 | return TestBedViewEngine;
|
---|
2500 | };
|
---|
2501 | /**
|
---|
2502 | * Allows overriding default compiler providers and settings
|
---|
2503 | * which are defined in test_injector.js
|
---|
2504 | */
|
---|
2505 | TestBedViewEngine.configureCompiler = function (config) {
|
---|
2506 | _getTestBedViewEngine().configureCompiler(config);
|
---|
2507 | return TestBedViewEngine;
|
---|
2508 | };
|
---|
2509 | /**
|
---|
2510 | * Allows overriding default providers, directives, pipes, modules of the test injector,
|
---|
2511 | * which are defined in test_injector.js
|
---|
2512 | */
|
---|
2513 | TestBedViewEngine.configureTestingModule = function (moduleDef) {
|
---|
2514 | _getTestBedViewEngine().configureTestingModule(moduleDef);
|
---|
2515 | return TestBedViewEngine;
|
---|
2516 | };
|
---|
2517 | /**
|
---|
2518 | * Compile components with a `templateUrl` for the test's NgModule.
|
---|
2519 | * It is necessary to call this function
|
---|
2520 | * as fetching urls is asynchronous.
|
---|
2521 | */
|
---|
2522 | TestBedViewEngine.compileComponents = function () {
|
---|
2523 | return getTestBed().compileComponents();
|
---|
2524 | };
|
---|
2525 | TestBedViewEngine.overrideModule = function (ngModule, override) {
|
---|
2526 | _getTestBedViewEngine().overrideModule(ngModule, override);
|
---|
2527 | return TestBedViewEngine;
|
---|
2528 | };
|
---|
2529 | TestBedViewEngine.overrideComponent = function (component, override) {
|
---|
2530 | _getTestBedViewEngine().overrideComponent(component, override);
|
---|
2531 | return TestBedViewEngine;
|
---|
2532 | };
|
---|
2533 | TestBedViewEngine.overrideDirective = function (directive, override) {
|
---|
2534 | _getTestBedViewEngine().overrideDirective(directive, override);
|
---|
2535 | return TestBedViewEngine;
|
---|
2536 | };
|
---|
2537 | TestBedViewEngine.overridePipe = function (pipe, override) {
|
---|
2538 | _getTestBedViewEngine().overridePipe(pipe, override);
|
---|
2539 | return TestBedViewEngine;
|
---|
2540 | };
|
---|
2541 | TestBedViewEngine.overrideTemplate = function (component, template) {
|
---|
2542 | _getTestBedViewEngine().overrideComponent(component, { set: { template: template, templateUrl: null } });
|
---|
2543 | return TestBedViewEngine;
|
---|
2544 | };
|
---|
2545 | /**
|
---|
2546 | * Overrides the template of the given component, compiling the template
|
---|
2547 | * in the context of the TestingModule.
|
---|
2548 | *
|
---|
2549 | * Note: This works for JIT and AOTed components as well.
|
---|
2550 | */
|
---|
2551 | TestBedViewEngine.overrideTemplateUsingTestingModule = function (component, template) {
|
---|
2552 | _getTestBedViewEngine().overrideTemplateUsingTestingModule(component, template);
|
---|
2553 | return TestBedViewEngine;
|
---|
2554 | };
|
---|
2555 | TestBedViewEngine.overrideProvider = function (token, provider) {
|
---|
2556 | _getTestBedViewEngine().overrideProvider(token, provider);
|
---|
2557 | return TestBedViewEngine;
|
---|
2558 | };
|
---|
2559 | TestBedViewEngine.inject = function (token, notFoundValue, flags) {
|
---|
2560 | return _getTestBedViewEngine().inject(token, notFoundValue, flags);
|
---|
2561 | };
|
---|
2562 | /** @deprecated from v9.0.0 use TestBed.inject */
|
---|
2563 | TestBedViewEngine.get = function (token, notFoundValue, flags) {
|
---|
2564 | if (notFoundValue === void 0) { notFoundValue = core.Injector.THROW_IF_NOT_FOUND; }
|
---|
2565 | if (flags === void 0) { flags = core.InjectFlags.Default; }
|
---|
2566 | return _getTestBedViewEngine().inject(token, notFoundValue, flags);
|
---|
2567 | };
|
---|
2568 | TestBedViewEngine.createComponent = function (component) {
|
---|
2569 | return _getTestBedViewEngine().createComponent(component);
|
---|
2570 | };
|
---|
2571 | TestBedViewEngine.shouldTearDownTestingModule = function () {
|
---|
2572 | return _getTestBedViewEngine().shouldTearDownTestingModule();
|
---|
2573 | };
|
---|
2574 | TestBedViewEngine.tearDownTestingModule = function () {
|
---|
2575 | _getTestBedViewEngine().tearDownTestingModule();
|
---|
2576 | };
|
---|
2577 | /**
|
---|
2578 | * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
---|
2579 | * angular module. These are common to every test in the suite.
|
---|
2580 | *
|
---|
2581 | * This may only be called once, to set up the common providers for the current test
|
---|
2582 | * suite on the current platform. If you absolutely need to change the providers,
|
---|
2583 | * first use `resetTestEnvironment`.
|
---|
2584 | *
|
---|
2585 | * Test modules and platforms for individual platforms are available from
|
---|
2586 | * '@angular/<platform_name>/testing'.
|
---|
2587 | */
|
---|
2588 | TestBedViewEngine.prototype.initTestEnvironment = function (ngModule, platform, summariesOrOptions) {
|
---|
2589 | if (this.platform || this.ngModule) {
|
---|
2590 | throw new Error('Cannot set base providers because it has already been called');
|
---|
2591 | }
|
---|
2592 | this.platform = platform;
|
---|
2593 | this.ngModule = ngModule;
|
---|
2594 | if (typeof summariesOrOptions === 'function') {
|
---|
2595 | this._testEnvAotSummaries = summariesOrOptions;
|
---|
2596 | TestBedViewEngine._environmentTeardownOptions = undefined;
|
---|
2597 | }
|
---|
2598 | else {
|
---|
2599 | this._testEnvAotSummaries = (summariesOrOptions === null || summariesOrOptions === void 0 ? void 0 : summariesOrOptions.aotSummaries) || (function () { return []; });
|
---|
2600 | TestBedViewEngine._environmentTeardownOptions = summariesOrOptions === null || summariesOrOptions === void 0 ? void 0 : summariesOrOptions.teardown;
|
---|
2601 | }
|
---|
2602 | };
|
---|
2603 | /**
|
---|
2604 | * Reset the providers for the test injector.
|
---|
2605 | */
|
---|
2606 | TestBedViewEngine.prototype.resetTestEnvironment = function () {
|
---|
2607 | this.resetTestingModule();
|
---|
2608 | this.platform = null;
|
---|
2609 | this.ngModule = null;
|
---|
2610 | this._testEnvAotSummaries = function () { return []; };
|
---|
2611 | TestBedViewEngine._environmentTeardownOptions = undefined;
|
---|
2612 | };
|
---|
2613 | TestBedViewEngine.prototype.resetTestingModule = function () {
|
---|
2614 | core.ɵclearOverrides();
|
---|
2615 | this._aotSummaries = [];
|
---|
2616 | this._templateOverrides = [];
|
---|
2617 | this._compiler = null;
|
---|
2618 | this._moduleOverrides = [];
|
---|
2619 | this._componentOverrides = [];
|
---|
2620 | this._directiveOverrides = [];
|
---|
2621 | this._pipeOverrides = [];
|
---|
2622 | this._isRoot = true;
|
---|
2623 | this._rootProviderOverrides = [];
|
---|
2624 | this._moduleFactory = null;
|
---|
2625 | this._pendingModuleFactory = null;
|
---|
2626 | this._compilerOptions = [];
|
---|
2627 | this._providers = [];
|
---|
2628 | this._declarations = [];
|
---|
2629 | this._imports = [];
|
---|
2630 | this._schemas = [];
|
---|
2631 | // We have to chain a couple of try/finally blocks, because each step can
|
---|
2632 | // throw errors and we don't want it to interrupt the next step and we also
|
---|
2633 | // want an error to be thrown at the end.
|
---|
2634 | try {
|
---|
2635 | this.destroyActiveFixtures();
|
---|
2636 | }
|
---|
2637 | finally {
|
---|
2638 | try {
|
---|
2639 | if (this.shouldTearDownTestingModule()) {
|
---|
2640 | this.tearDownTestingModule();
|
---|
2641 | }
|
---|
2642 | }
|
---|
2643 | finally {
|
---|
2644 | this._moduleRef = null;
|
---|
2645 | this._instanceTeardownOptions = undefined;
|
---|
2646 | this._instantiated = false;
|
---|
2647 | }
|
---|
2648 | }
|
---|
2649 | };
|
---|
2650 | TestBedViewEngine.prototype.configureCompiler = function (config) {
|
---|
2651 | this._assertNotInstantiated('TestBed.configureCompiler', 'configure the compiler');
|
---|
2652 | this._compilerOptions.push(config);
|
---|
2653 | };
|
---|
2654 | TestBedViewEngine.prototype.configureTestingModule = function (moduleDef) {
|
---|
2655 | var _f, _g, _h, _j;
|
---|
2656 | this._assertNotInstantiated('TestBed.configureTestingModule', 'configure the test module');
|
---|
2657 | if (moduleDef.providers) {
|
---|
2658 | (_f = this._providers).push.apply(_f, __spreadArray([], __read(moduleDef.providers)));
|
---|
2659 | }
|
---|
2660 | if (moduleDef.declarations) {
|
---|
2661 | (_g = this._declarations).push.apply(_g, __spreadArray([], __read(moduleDef.declarations)));
|
---|
2662 | }
|
---|
2663 | if (moduleDef.imports) {
|
---|
2664 | (_h = this._imports).push.apply(_h, __spreadArray([], __read(moduleDef.imports)));
|
---|
2665 | }
|
---|
2666 | if (moduleDef.schemas) {
|
---|
2667 | (_j = this._schemas).push.apply(_j, __spreadArray([], __read(moduleDef.schemas)));
|
---|
2668 | }
|
---|
2669 | if (moduleDef.aotSummaries) {
|
---|
2670 | this._aotSummaries.push(moduleDef.aotSummaries);
|
---|
2671 | }
|
---|
2672 | // Always re-assign the teardown options, even if they're undefined.
|
---|
2673 | // This ensures that we don't carry the options between tests.
|
---|
2674 | this._instanceTeardownOptions = moduleDef.teardown;
|
---|
2675 | };
|
---|
2676 | TestBedViewEngine.prototype.compileComponents = function () {
|
---|
2677 | var _this = this;
|
---|
2678 | if (this._moduleFactory || this._instantiated) {
|
---|
2679 | return Promise.resolve(null);
|
---|
2680 | }
|
---|
2681 | var moduleType = this._createCompilerAndModule();
|
---|
2682 | this._pendingModuleFactory = moduleType;
|
---|
2683 | return this._compiler.compileModuleAndAllComponentsAsync(moduleType).then(function (result) {
|
---|
2684 | // If the module mismatches by the time the promise resolves, it means that the module has
|
---|
2685 | // already been destroyed and a new compilation has started. If that's the case, avoid
|
---|
2686 | // overwriting the module factory, because it can cause downstream errors.
|
---|
2687 | if (_this._pendingModuleFactory === moduleType) {
|
---|
2688 | _this._moduleFactory = result.ngModuleFactory;
|
---|
2689 | _this._pendingModuleFactory = null;
|
---|
2690 | }
|
---|
2691 | });
|
---|
2692 | };
|
---|
2693 | TestBedViewEngine.prototype._initIfNeeded = function () {
|
---|
2694 | var e_1, _f;
|
---|
2695 | if (this._instantiated) {
|
---|
2696 | return;
|
---|
2697 | }
|
---|
2698 | if (!this._moduleFactory) {
|
---|
2699 | try {
|
---|
2700 | var moduleType = this._createCompilerAndModule();
|
---|
2701 | this._moduleFactory =
|
---|
2702 | this._compiler.compileModuleAndAllComponentsSync(moduleType).ngModuleFactory;
|
---|
2703 | }
|
---|
2704 | catch (e) {
|
---|
2705 | var errorCompType = this._compiler.getComponentFromError(e);
|
---|
2706 | if (errorCompType) {
|
---|
2707 | throw new Error("This test module uses the component " + core.ɵstringify(errorCompType) + " which is using a \"templateUrl\" or \"styleUrls\", but they were never compiled. " +
|
---|
2708 | "Please call \"TestBed.compileComponents\" before your test.");
|
---|
2709 | }
|
---|
2710 | else {
|
---|
2711 | throw e;
|
---|
2712 | }
|
---|
2713 | }
|
---|
2714 | }
|
---|
2715 | try {
|
---|
2716 | for (var _g = __values(this._templateOverrides), _h = _g.next(); !_h.done; _h = _g.next()) {
|
---|
2717 | var _j = _h.value, component = _j.component, templateOf = _j.templateOf;
|
---|
2718 | var compFactory = this._compiler.getComponentFactory(templateOf);
|
---|
2719 | core.ɵoverrideComponentView(component, compFactory);
|
---|
2720 | }
|
---|
2721 | }
|
---|
2722 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
---|
2723 | finally {
|
---|
2724 | try {
|
---|
2725 | if (_h && !_h.done && (_f = _g.return)) _f.call(_g);
|
---|
2726 | }
|
---|
2727 | finally { if (e_1) throw e_1.error; }
|
---|
2728 | }
|
---|
2729 | var ngZone = new core.NgZone({ enableLongStackTrace: true, shouldCoalesceEventChangeDetection: false });
|
---|
2730 | var providers = [{ provide: core.NgZone, useValue: ngZone }];
|
---|
2731 | var ngZoneInjector = core.Injector.create({
|
---|
2732 | providers: providers,
|
---|
2733 | parent: this.platform.injector,
|
---|
2734 | name: this._moduleFactory.moduleType.name
|
---|
2735 | });
|
---|
2736 | this._moduleRef = this._moduleFactory.create(ngZoneInjector);
|
---|
2737 | // ApplicationInitStatus.runInitializers() is marked @internal to core. So casting to any
|
---|
2738 | // before accessing it.
|
---|
2739 | this._moduleRef.injector.get(core.ApplicationInitStatus).runInitializers();
|
---|
2740 | this._instantiated = true;
|
---|
2741 | };
|
---|
2742 | TestBedViewEngine.prototype._createCompilerAndModule = function () {
|
---|
2743 | var e_2, _f;
|
---|
2744 | var _this = this;
|
---|
2745 | var providers = this._providers.concat([{ provide: TestBed, useValue: this }]);
|
---|
2746 | var declarations = __spreadArray(__spreadArray([], __read(this._declarations)), __read(this._templateOverrides.map(function (entry) { return entry.templateOf; })));
|
---|
2747 | var rootScopeImports = [];
|
---|
2748 | var rootProviderOverrides = this._rootProviderOverrides;
|
---|
2749 | if (this._isRoot) {
|
---|
2750 | var RootScopeModule = /** @class */ (function () {
|
---|
2751 | function RootScopeModule() {
|
---|
2752 | }
|
---|
2753 | return RootScopeModule;
|
---|
2754 | }());
|
---|
2755 | RootScopeModule.decorators = [
|
---|
2756 | { type: core.NgModule, args: [{
|
---|
2757 | providers: __spreadArray([], __read(rootProviderOverrides)),
|
---|
2758 | jit: true,
|
---|
2759 | },] }
|
---|
2760 | ];
|
---|
2761 | rootScopeImports.push(RootScopeModule);
|
---|
2762 | }
|
---|
2763 | providers.push({ provide: core.ɵINJECTOR_SCOPE, useValue: this._isRoot ? 'root' : null });
|
---|
2764 | var imports = [rootScopeImports, this.ngModule, this._imports];
|
---|
2765 | var schemas = this._schemas;
|
---|
2766 | var DynamicTestModule = /** @class */ (function () {
|
---|
2767 | function DynamicTestModule() {
|
---|
2768 | }
|
---|
2769 | return DynamicTestModule;
|
---|
2770 | }());
|
---|
2771 | DynamicTestModule.decorators = [
|
---|
2772 | { type: core.NgModule, args: [{ providers: providers, declarations: declarations, imports: imports, schemas: schemas, jit: true },] }
|
---|
2773 | ];
|
---|
2774 | var compilerFactory = this.platform.injector.get(TestingCompilerFactory);
|
---|
2775 | this._compiler = compilerFactory.createTestingCompiler(this._compilerOptions);
|
---|
2776 | try {
|
---|
2777 | for (var _g = __values(__spreadArray([this._testEnvAotSummaries], __read(this._aotSummaries))), _h = _g.next(); !_h.done; _h = _g.next()) {
|
---|
2778 | var summary = _h.value;
|
---|
2779 | this._compiler.loadAotSummaries(summary);
|
---|
2780 | }
|
---|
2781 | }
|
---|
2782 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
---|
2783 | finally {
|
---|
2784 | try {
|
---|
2785 | if (_h && !_h.done && (_f = _g.return)) _f.call(_g);
|
---|
2786 | }
|
---|
2787 | finally { if (e_2) throw e_2.error; }
|
---|
2788 | }
|
---|
2789 | this._moduleOverrides.forEach(function (entry) { return _this._compiler.overrideModule(entry[0], entry[1]); });
|
---|
2790 | this._componentOverrides.forEach(function (entry) { return _this._compiler.overrideComponent(entry[0], entry[1]); });
|
---|
2791 | this._directiveOverrides.forEach(function (entry) { return _this._compiler.overrideDirective(entry[0], entry[1]); });
|
---|
2792 | this._pipeOverrides.forEach(function (entry) { return _this._compiler.overridePipe(entry[0], entry[1]); });
|
---|
2793 | return DynamicTestModule;
|
---|
2794 | };
|
---|
2795 | TestBedViewEngine.prototype._assertNotInstantiated = function (methodName, methodDescription) {
|
---|
2796 | if (this._instantiated) {
|
---|
2797 | throw new Error("Cannot " + methodDescription + " when the test module has already been instantiated. " +
|
---|
2798 | ("Make sure you are not using `inject` before `" + methodName + "`."));
|
---|
2799 | }
|
---|
2800 | };
|
---|
2801 | TestBedViewEngine.prototype.inject = function (token, notFoundValue, flags) {
|
---|
2802 | this._initIfNeeded();
|
---|
2803 | if (token === TestBed) {
|
---|
2804 | return this;
|
---|
2805 | }
|
---|
2806 | // Tests can inject things from the ng module and from the compiler,
|
---|
2807 | // but the ng module can't inject things from the compiler and vice versa.
|
---|
2808 | var UNDEFINED = {};
|
---|
2809 | var result = this._moduleRef.injector.get(token, UNDEFINED, flags);
|
---|
2810 | return result === UNDEFINED ? this._compiler.injector.get(token, notFoundValue, flags) :
|
---|
2811 | result;
|
---|
2812 | };
|
---|
2813 | /** @deprecated from v9.0.0 use TestBed.inject */
|
---|
2814 | TestBedViewEngine.prototype.get = function (token, notFoundValue, flags) {
|
---|
2815 | if (notFoundValue === void 0) { notFoundValue = core.Injector.THROW_IF_NOT_FOUND; }
|
---|
2816 | if (flags === void 0) { flags = core.InjectFlags.Default; }
|
---|
2817 | return this.inject(token, notFoundValue, flags);
|
---|
2818 | };
|
---|
2819 | TestBedViewEngine.prototype.execute = function (tokens, fn, context) {
|
---|
2820 | var _this = this;
|
---|
2821 | this._initIfNeeded();
|
---|
2822 | var params = tokens.map(function (t) { return _this.inject(t); });
|
---|
2823 | return fn.apply(context, params);
|
---|
2824 | };
|
---|
2825 | TestBedViewEngine.prototype.overrideModule = function (ngModule, override) {
|
---|
2826 | this._assertNotInstantiated('overrideModule', 'override module metadata');
|
---|
2827 | this._moduleOverrides.push([ngModule, override]);
|
---|
2828 | };
|
---|
2829 | TestBedViewEngine.prototype.overrideComponent = function (component, override) {
|
---|
2830 | this._assertNotInstantiated('overrideComponent', 'override component metadata');
|
---|
2831 | this._componentOverrides.push([component, override]);
|
---|
2832 | };
|
---|
2833 | TestBedViewEngine.prototype.overrideDirective = function (directive, override) {
|
---|
2834 | this._assertNotInstantiated('overrideDirective', 'override directive metadata');
|
---|
2835 | this._directiveOverrides.push([directive, override]);
|
---|
2836 | };
|
---|
2837 | TestBedViewEngine.prototype.overridePipe = function (pipe, override) {
|
---|
2838 | this._assertNotInstantiated('overridePipe', 'override pipe metadata');
|
---|
2839 | this._pipeOverrides.push([pipe, override]);
|
---|
2840 | };
|
---|
2841 | TestBedViewEngine.prototype.overrideProvider = function (token, provider) {
|
---|
2842 | this._assertNotInstantiated('overrideProvider', 'override provider');
|
---|
2843 | this.overrideProviderImpl(token, provider);
|
---|
2844 | };
|
---|
2845 | TestBedViewEngine.prototype.overrideProviderImpl = function (token, provider, deprecated) {
|
---|
2846 | if (deprecated === void 0) { deprecated = false; }
|
---|
2847 | var def = null;
|
---|
2848 | if (typeof token !== 'string' && (def = core.ɵgetInjectableDef(token)) && def.providedIn === 'root') {
|
---|
2849 | if (provider.useFactory) {
|
---|
2850 | this._rootProviderOverrides.push({ provide: token, useFactory: provider.useFactory, deps: provider.deps || [] });
|
---|
2851 | }
|
---|
2852 | else {
|
---|
2853 | this._rootProviderOverrides.push({ provide: token, useValue: provider.useValue });
|
---|
2854 | }
|
---|
2855 | }
|
---|
2856 | var flags = 0;
|
---|
2857 | var value;
|
---|
2858 | if (provider.useFactory) {
|
---|
2859 | flags |= 1024 /* TypeFactoryProvider */;
|
---|
2860 | value = provider.useFactory;
|
---|
2861 | }
|
---|
2862 | else {
|
---|
2863 | flags |= 256 /* TypeValueProvider */;
|
---|
2864 | value = provider.useValue;
|
---|
2865 | }
|
---|
2866 | var deps = (provider.deps || []).map(function (dep) {
|
---|
2867 | var depFlags = 0 /* None */;
|
---|
2868 | var depToken;
|
---|
2869 | if (Array.isArray(dep)) {
|
---|
2870 | dep.forEach(function (entry) {
|
---|
2871 | if (entry instanceof core.Optional) {
|
---|
2872 | depFlags |= 2 /* Optional */;
|
---|
2873 | }
|
---|
2874 | else if (entry instanceof core.SkipSelf) {
|
---|
2875 | depFlags |= 1 /* SkipSelf */;
|
---|
2876 | }
|
---|
2877 | else {
|
---|
2878 | depToken = entry;
|
---|
2879 | }
|
---|
2880 | });
|
---|
2881 | }
|
---|
2882 | else {
|
---|
2883 | depToken = dep;
|
---|
2884 | }
|
---|
2885 | return [depFlags, depToken];
|
---|
2886 | });
|
---|
2887 | core.ɵoverrideProvider({ token: token, flags: flags, deps: deps, value: value, deprecatedBehavior: deprecated });
|
---|
2888 | };
|
---|
2889 | TestBedViewEngine.prototype.overrideTemplateUsingTestingModule = function (component, template) {
|
---|
2890 | this._assertNotInstantiated('overrideTemplateUsingTestingModule', 'override template');
|
---|
2891 | var OverrideComponent = /** @class */ (function () {
|
---|
2892 | function OverrideComponent() {
|
---|
2893 | }
|
---|
2894 | return OverrideComponent;
|
---|
2895 | }());
|
---|
2896 | OverrideComponent.decorators = [
|
---|
2897 | { type: core.Component, args: [{ selector: 'empty', template: template, jit: true },] }
|
---|
2898 | ];
|
---|
2899 | this._templateOverrides.push({ component: component, templateOf: OverrideComponent });
|
---|
2900 | };
|
---|
2901 | TestBedViewEngine.prototype.createComponent = function (component) {
|
---|
2902 | var _this = this;
|
---|
2903 | this._initIfNeeded();
|
---|
2904 | var componentFactory = this._compiler.getComponentFactory(component);
|
---|
2905 | if (!componentFactory) {
|
---|
2906 | throw new Error("Cannot create the component " + core.ɵstringify(component) + " as it was not imported into the testing module!");
|
---|
2907 | }
|
---|
2908 | // TODO: Don't cast as `InjectionToken<boolean>`, declared type is boolean[]
|
---|
2909 | var noNgZone = this.inject(ComponentFixtureNoNgZone, false);
|
---|
2910 | // TODO: Don't cast as `InjectionToken<boolean>`, declared type is boolean[]
|
---|
2911 | var autoDetect = this.inject(ComponentFixtureAutoDetect, false);
|
---|
2912 | var ngZone = noNgZone ? null : this.inject(core.NgZone, null);
|
---|
2913 | var testComponentRenderer = this.inject(TestComponentRenderer);
|
---|
2914 | var rootElId = "root" + _nextRootElementId$1++;
|
---|
2915 | testComponentRenderer.insertRootElement(rootElId);
|
---|
2916 | var initComponent = function () {
|
---|
2917 | var componentRef = componentFactory.create(core.Injector.NULL, [], "#" + rootElId, _this._moduleRef);
|
---|
2918 | return new ComponentFixture(componentRef, ngZone, autoDetect);
|
---|
2919 | };
|
---|
2920 | var fixture = !ngZone ? initComponent() : ngZone.run(initComponent);
|
---|
2921 | this._activeFixtures.push(fixture);
|
---|
2922 | return fixture;
|
---|
2923 | };
|
---|
2924 | TestBedViewEngine.prototype.destroyActiveFixtures = function () {
|
---|
2925 | var errorCount = 0;
|
---|
2926 | this._activeFixtures.forEach(function (fixture) {
|
---|
2927 | try {
|
---|
2928 | fixture.destroy();
|
---|
2929 | }
|
---|
2930 | catch (e) {
|
---|
2931 | errorCount++;
|
---|
2932 | console.error('Error during cleanup of component', {
|
---|
2933 | component: fixture.componentInstance,
|
---|
2934 | stacktrace: e,
|
---|
2935 | });
|
---|
2936 | }
|
---|
2937 | });
|
---|
2938 | this._activeFixtures = [];
|
---|
2939 | if (errorCount > 0 && this.shouldRethrowTeardownErrors()) {
|
---|
2940 | throw Error(errorCount + " " + (errorCount === 1 ? 'component' : 'components') + " " +
|
---|
2941 | "threw errors during cleanup");
|
---|
2942 | }
|
---|
2943 | };
|
---|
2944 | TestBedViewEngine.prototype.shouldRethrowTeardownErrors = function () {
|
---|
2945 | var _a, _b;
|
---|
2946 | var instanceOptions = this._instanceTeardownOptions;
|
---|
2947 | var environmentOptions = TestBedViewEngine._environmentTeardownOptions;
|
---|
2948 | // If the new teardown behavior hasn't been configured, preserve the old behavior.
|
---|
2949 | if (!instanceOptions && !environmentOptions) {
|
---|
2950 | return false;
|
---|
2951 | }
|
---|
2952 | // Otherwise use the configured behavior or default to rethrowing.
|
---|
2953 | return (_b = (_a = instanceOptions === null || instanceOptions === void 0 ? void 0 : instanceOptions.rethrowErrors) !== null && _a !== void 0 ? _a : environmentOptions === null || environmentOptions === void 0 ? void 0 : environmentOptions.rethrowErrors) !== null && _b !== void 0 ? _b : true;
|
---|
2954 | };
|
---|
2955 | TestBedViewEngine.prototype.shouldTearDownTestingModule = function () {
|
---|
2956 | var _a, _b, _c, _d;
|
---|
2957 | return (_d = (_b = (_a = this._instanceTeardownOptions) === null || _a === void 0 ? void 0 : _a.destroyAfterEach) !== null && _b !== void 0 ? _b : (_c = TestBedViewEngine._environmentTeardownOptions) === null || _c === void 0 ? void 0 : _c.destroyAfterEach) !== null && _d !== void 0 ? _d : TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT;
|
---|
2958 | };
|
---|
2959 | TestBedViewEngine.prototype.tearDownTestingModule = function () {
|
---|
2960 | var _a, _b, _c, _d, _e;
|
---|
2961 | // If the module ref has already been destroyed, we won't be able to get a test renderer.
|
---|
2962 | if (this._moduleRef === null) {
|
---|
2963 | return;
|
---|
2964 | }
|
---|
2965 | // Resolve the renderer ahead of time, because we want to remove the root elements as the very
|
---|
2966 | // last step, but the injector will be destroyed as a part of the module ref destruction.
|
---|
2967 | var testRenderer = this.inject(TestComponentRenderer);
|
---|
2968 | try {
|
---|
2969 | this._moduleRef.destroy();
|
---|
2970 | }
|
---|
2971 | catch (e) {
|
---|
2972 | if ((_d = (_b = (_a = this._instanceTeardownOptions) === null || _a === void 0 ? void 0 : _a.rethrowErrors) !== null && _b !== void 0 ? _b : (_c = TestBedViewEngine._environmentTeardownOptions) === null || _c === void 0 ? void 0 : _c.rethrowErrors) !== null && _d !== void 0 ? _d : true) {
|
---|
2973 | throw e;
|
---|
2974 | }
|
---|
2975 | else {
|
---|
2976 | console.error('Error during cleanup of a testing module', {
|
---|
2977 | component: this._moduleRef.instance,
|
---|
2978 | stacktrace: e,
|
---|
2979 | });
|
---|
2980 | }
|
---|
2981 | }
|
---|
2982 | finally {
|
---|
2983 | (_e = testRenderer === null || testRenderer === void 0 ? void 0 : testRenderer.removeAllRootElements) === null || _e === void 0 ? void 0 : _e.call(testRenderer);
|
---|
2984 | }
|
---|
2985 | };
|
---|
2986 | return TestBedViewEngine;
|
---|
2987 | }());
|
---|
2988 | /**
|
---|
2989 | * @description
|
---|
2990 | * Configures and initializes environment for unit testing and provides methods for
|
---|
2991 | * creating components and services in unit tests.
|
---|
2992 | *
|
---|
2993 | * `TestBed` is the primary api for writing unit tests for Angular applications and libraries.
|
---|
2994 | *
|
---|
2995 | * Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
|
---|
2996 | * according to the compiler used.
|
---|
2997 | *
|
---|
2998 | * @publicApi
|
---|
2999 | */
|
---|
3000 | var TestBed = core.ɵivyEnabled ? TestBedRender3 : TestBedViewEngine;
|
---|
3001 | /**
|
---|
3002 | * Returns a singleton of the applicable `TestBed`.
|
---|
3003 | *
|
---|
3004 | * It will be either an instance of `TestBedViewEngine` or `TestBedRender3`.
|
---|
3005 | *
|
---|
3006 | * @publicApi
|
---|
3007 | */
|
---|
3008 | var getTestBed = core.ɵivyEnabled ? _getTestBedRender3 : _getTestBedViewEngine;
|
---|
3009 | var testBed$1;
|
---|
3010 | function _getTestBedViewEngine() {
|
---|
3011 | return testBed$1 = testBed$1 || new TestBedViewEngine();
|
---|
3012 | }
|
---|
3013 | /**
|
---|
3014 | * Allows injecting dependencies in `beforeEach()` and `it()`.
|
---|
3015 | *
|
---|
3016 | * Example:
|
---|
3017 | *
|
---|
3018 | * ```
|
---|
3019 | * beforeEach(inject([Dependency, AClass], (dep, object) => {
|
---|
3020 | * // some code that uses `dep` and `object`
|
---|
3021 | * // ...
|
---|
3022 | * }));
|
---|
3023 | *
|
---|
3024 | * it('...', inject([AClass], (object) => {
|
---|
3025 | * object.doSomething();
|
---|
3026 | * expect(...);
|
---|
3027 | * })
|
---|
3028 | * ```
|
---|
3029 | *
|
---|
3030 | * @publicApi
|
---|
3031 | */
|
---|
3032 | function inject(tokens, fn) {
|
---|
3033 | var testBed = getTestBed();
|
---|
3034 | // Not using an arrow function to preserve context passed from call site
|
---|
3035 | return function () {
|
---|
3036 | return testBed.execute(tokens, fn, this);
|
---|
3037 | };
|
---|
3038 | }
|
---|
3039 | /**
|
---|
3040 | * @publicApi
|
---|
3041 | */
|
---|
3042 | var InjectSetupWrapper = /** @class */ (function () {
|
---|
3043 | function InjectSetupWrapper(_moduleDef) {
|
---|
3044 | this._moduleDef = _moduleDef;
|
---|
3045 | }
|
---|
3046 | InjectSetupWrapper.prototype._addModule = function () {
|
---|
3047 | var moduleDef = this._moduleDef();
|
---|
3048 | if (moduleDef) {
|
---|
3049 | getTestBed().configureTestingModule(moduleDef);
|
---|
3050 | }
|
---|
3051 | };
|
---|
3052 | InjectSetupWrapper.prototype.inject = function (tokens, fn) {
|
---|
3053 | var self = this;
|
---|
3054 | // Not using an arrow function to preserve context passed from call site
|
---|
3055 | return function () {
|
---|
3056 | self._addModule();
|
---|
3057 | return inject(tokens, fn).call(this);
|
---|
3058 | };
|
---|
3059 | };
|
---|
3060 | return InjectSetupWrapper;
|
---|
3061 | }());
|
---|
3062 | function withModule(moduleDef, fn) {
|
---|
3063 | if (fn) {
|
---|
3064 | // Not using an arrow function to preserve context passed from call site
|
---|
3065 | return function () {
|
---|
3066 | var testBed = getTestBed();
|
---|
3067 | if (moduleDef) {
|
---|
3068 | testBed.configureTestingModule(moduleDef);
|
---|
3069 | }
|
---|
3070 | return fn.apply(this);
|
---|
3071 | };
|
---|
3072 | }
|
---|
3073 | return new InjectSetupWrapper(function () { return moduleDef; });
|
---|
3074 | }
|
---|
3075 |
|
---|
3076 | /**
|
---|
3077 | * @license
|
---|
3078 | * Copyright Google LLC All Rights Reserved.
|
---|
3079 | *
|
---|
3080 | * Use of this source code is governed by an MIT-style license that can be
|
---|
3081 | * found in the LICENSE file at https://angular.io/license
|
---|
3082 | */
|
---|
3083 | var _global = (typeof window === 'undefined' ? global : window);
|
---|
3084 | // Reset the test providers and the fake async zone before each test.
|
---|
3085 | if (_global.beforeEach) {
|
---|
3086 | _global.beforeEach(getCleanupHook(false));
|
---|
3087 | }
|
---|
3088 | // We provide both a `beforeEach` and `afterEach`, because the updated behavior for
|
---|
3089 | // tearing down the module is supposed to run after the test so that we can associate
|
---|
3090 | // teardown errors with the correct test.
|
---|
3091 | if (_global.afterEach) {
|
---|
3092 | _global.afterEach(getCleanupHook(true));
|
---|
3093 | }
|
---|
3094 | function getCleanupHook(expectedTeardownValue) {
|
---|
3095 | return function () {
|
---|
3096 | if (TestBed.shouldTearDownTestingModule() ===
|
---|
3097 | expectedTeardownValue) {
|
---|
3098 | TestBed.resetTestingModule();
|
---|
3099 | resetFakeAsyncZone();
|
---|
3100 | }
|
---|
3101 | };
|
---|
3102 | }
|
---|
3103 | /**
|
---|
3104 | * This API should be removed. But doing so seems to break `google3` and so it requires a bit of
|
---|
3105 | * investigation.
|
---|
3106 | *
|
---|
3107 | * A work around is to mark it as `@codeGenApi` for now and investigate later.
|
---|
3108 | *
|
---|
3109 | * @codeGenApi
|
---|
3110 | */
|
---|
3111 | // TODO(iminar): Remove this code in a safe way.
|
---|
3112 | var __core_private_testing_placeholder__ = '';
|
---|
3113 |
|
---|
3114 | /**
|
---|
3115 | * @license
|
---|
3116 | * Copyright Google LLC All Rights Reserved.
|
---|
3117 | *
|
---|
3118 | * Use of this source code is governed by an MIT-style license that can be
|
---|
3119 | * found in the LICENSE file at https://angular.io/license
|
---|
3120 | */
|
---|
3121 |
|
---|
3122 | /**
|
---|
3123 | * @license
|
---|
3124 | * Copyright Google LLC All Rights Reserved.
|
---|
3125 | *
|
---|
3126 | * Use of this source code is governed by an MIT-style license that can be
|
---|
3127 | * found in the LICENSE file at https://angular.io/license
|
---|
3128 | */
|
---|
3129 |
|
---|
3130 | /**
|
---|
3131 | * @license
|
---|
3132 | * Copyright Google LLC All Rights Reserved.
|
---|
3133 | *
|
---|
3134 | * Use of this source code is governed by an MIT-style license that can be
|
---|
3135 | * found in the LICENSE file at https://angular.io/license
|
---|
3136 | */
|
---|
3137 | // This file only reexports content of the `src` folder. Keep it that way.
|
---|
3138 |
|
---|
3139 | /**
|
---|
3140 | * @license
|
---|
3141 | * Copyright Google LLC All Rights Reserved.
|
---|
3142 | *
|
---|
3143 | * Use of this source code is governed by an MIT-style license that can be
|
---|
3144 | * found in the LICENSE file at https://angular.io/license
|
---|
3145 | */
|
---|
3146 |
|
---|
3147 | /**
|
---|
3148 | * Generated bundle index. Do not edit.
|
---|
3149 | */
|
---|
3150 |
|
---|
3151 | exports.ComponentFixture = ComponentFixture;
|
---|
3152 | exports.ComponentFixtureAutoDetect = ComponentFixtureAutoDetect;
|
---|
3153 | exports.ComponentFixtureNoNgZone = ComponentFixtureNoNgZone;
|
---|
3154 | exports.InjectSetupWrapper = InjectSetupWrapper;
|
---|
3155 | exports.TestBed = TestBed;
|
---|
3156 | exports.TestComponentRenderer = TestComponentRenderer;
|
---|
3157 | exports.__core_private_testing_placeholder__ = __core_private_testing_placeholder__;
|
---|
3158 | exports.async = async;
|
---|
3159 | exports.discardPeriodicTasks = discardPeriodicTasks;
|
---|
3160 | exports.fakeAsync = fakeAsync;
|
---|
3161 | exports.flush = flush;
|
---|
3162 | exports.flushMicrotasks = flushMicrotasks;
|
---|
3163 | exports.getTestBed = getTestBed;
|
---|
3164 | exports.inject = inject;
|
---|
3165 | exports.resetFakeAsyncZone = resetFakeAsyncZone;
|
---|
3166 | exports.tick = tick;
|
---|
3167 | exports.waitForAsync = waitForAsync;
|
---|
3168 | exports.withModule = withModule;
|
---|
3169 | exports.ɵMetadataOverrider = MetadataOverrider;
|
---|
3170 | exports.ɵTestingCompiler = TestingCompiler;
|
---|
3171 | exports.ɵTestingCompilerFactory = TestingCompilerFactory;
|
---|
3172 | exports.ɵangular_packages_core_testing_testing_a = TestBedViewEngine;
|
---|
3173 | exports.ɵangular_packages_core_testing_testing_b = TestBedRender3;
|
---|
3174 | exports.ɵangular_packages_core_testing_testing_c = _getTestBedRender3;
|
---|
3175 |
|
---|
3176 | Object.defineProperty(exports, '__esModule', { value: true });
|
---|
3177 |
|
---|
3178 | })));
|
---|
3179 | //# sourceMappingURL=core-testing.umd.js.map
|
---|