UNPKG

@angular/core

Version:

Angular - the core framework

1,215 lines (1,179 loc) 146 kB
/** * @license Angular v9.1.11 * (c) 2010-2020 Google LLC. https://angular.io/ * License: MIT */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/compiler')) : typeof define === 'function' && define.amd ? define('@angular/core/testing', ['exports', '@angular/core', '@angular/compiler'], factory) : (global = global || self, factory((global.ng = global.ng || {}, global.ng.core = global.ng.core || {}, global.ng.core.testing = {}), global.ng.core, global.ng.compiler)); }(this, (function (exports, core, compiler) { 'use strict'; /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ var _global = (typeof window === 'undefined' ? global : window); /** * Wraps a test function in an asynchronous test zone. The test will automatically * complete when all asynchronous calls within this zone are done. Can be used * to wrap an {@link inject} call. * * Example: * * ``` * it('...', async(inject([AClass], (object) => { * object.doSomething.then(() => { * expect(...); * }) * }); * ``` * * */ function asyncFallback(fn) { // If we're running using the Jasmine test framework, adapt to call the 'done' // function when asynchronous activity is finished. if (_global.jasmine) { // Not using an arrow function to preserve context passed from call site return function (done) { if (!done) { // if we run beforeEach in @angular/core/testing/testing_internal then we get no done // fake it here and assume sync. done = function () { }; done.fail = function (e) { throw e; }; } runInTestZone(fn, this, done, function (err) { if (typeof err === 'string') { return done.fail(new Error(err)); } else { done.fail(err); } }); }; } // Otherwise, return a promise which will resolve when asynchronous activity // is finished. This will be correctly consumed by the Mocha framework with // it('...', async(myFn)); or can be used in a custom framework. // Not using an arrow function to preserve context passed from call site return function () { var _this = this; return new Promise(function (finishCallback, failCallback) { runInTestZone(fn, _this, finishCallback, failCallback); }); }; } function runInTestZone(fn, context, finishCallback, failCallback) { var currentZone = Zone.current; var AsyncTestZoneSpec = Zone['AsyncTestZoneSpec']; if (AsyncTestZoneSpec === undefined) { throw new Error('AsyncTestZoneSpec is needed for the async() test helper but could not be found. ' + 'Please make sure that your environment includes zone.js/dist/async-test.js'); } var ProxyZoneSpec = Zone['ProxyZoneSpec']; if (ProxyZoneSpec === undefined) { throw new Error('ProxyZoneSpec is needed for the async() test helper but could not be found. ' + 'Please make sure that your environment includes zone.js/dist/proxy.js'); } var proxyZoneSpec = ProxyZoneSpec.get(); ProxyZoneSpec.assertPresent(); // We need to create the AsyncTestZoneSpec outside the ProxyZone. // If we do it in ProxyZone then we will get to infinite recursion. var proxyZone = Zone.current.getZoneWith('ProxyZoneSpec'); var previousDelegate = proxyZoneSpec.getDelegate(); proxyZone.parent.run(function () { var testZoneSpec = new AsyncTestZoneSpec(function () { // Need to restore the original zone. currentZone.run(function () { if (proxyZoneSpec.getDelegate() == testZoneSpec) { // Only reset the zone spec if it's sill this one. Otherwise, assume it's OK. proxyZoneSpec.setDelegate(previousDelegate); } finishCallback(); }); }, function (error) { // Need to restore the original zone. currentZone.run(function () { if (proxyZoneSpec.getDelegate() == testZoneSpec) { // Only reset the zone spec if it's sill this one. Otherwise, assume it's OK. proxyZoneSpec.setDelegate(previousDelegate); } failCallback(error); }); }, 'test'); proxyZoneSpec.setDelegate(testZoneSpec); }); return Zone.current.runGuarded(fn, context); } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * Wraps a test function in an asynchronous test zone. The test will automatically * complete when all asynchronous calls within this zone are done. Can be used * to wrap an {@link inject} call. * * Example: * * ``` * it('...', async(inject([AClass], (object) => { * object.doSomething.then(() => { * expect(...); * }) * }); * ``` * * @publicApi */ function async(fn) { var _Zone = typeof Zone !== 'undefined' ? Zone : null; if (!_Zone) { return function () { return Promise.reject('Zone is needed for the async() test helper but could not be found. ' + 'Please make sure that your environment includes zone.js/dist/zone.js'); }; } var asyncTest = _Zone && _Zone[_Zone.__symbol__('asyncTest')]; if (typeof asyncTest === 'function') { return asyncTest(fn); } // not using new version of zone.js // TODO @JiaLiPassion, remove this after all library updated to // newest version of zone.js(0.8.25) return asyncFallback(fn); } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * Fixture for debugging and testing a component. * * @publicApi */ var ComponentFixture = /** @class */ (function () { function ComponentFixture(componentRef, ngZone, _autoDetect) { var _this = this; this.componentRef = componentRef; this.ngZone = ngZone; this._autoDetect = _autoDetect; this._isStable = true; this._isDestroyed = false; this._resolve = null; this._promise = null; this._onUnstableSubscription = null; this._onStableSubscription = null; this._onMicrotaskEmptySubscription = null; this._onErrorSubscription = null; this.changeDetectorRef = componentRef.changeDetectorRef; this.elementRef = componentRef.location; this.debugElement = core.getDebugNode(this.elementRef.nativeElement); this.componentInstance = componentRef.instance; this.nativeElement = this.elementRef.nativeElement; this.componentRef = componentRef; this.ngZone = ngZone; if (ngZone) { // Create subscriptions outside the NgZone so that the callbacks run oustide // of NgZone. ngZone.runOutsideAngular(function () { _this._onUnstableSubscription = ngZone.onUnstable.subscribe({ next: function () { _this._isStable = false; } }); _this._onMicrotaskEmptySubscription = ngZone.onMicrotaskEmpty.subscribe({ next: function () { if (_this._autoDetect) { // Do a change detection run with checkNoChanges set to true to check // there are no changes on the second run. _this.detectChanges(true); } } }); _this._onStableSubscription = ngZone.onStable.subscribe({ next: function () { _this._isStable = true; // Check whether there is a pending whenStable() completer to resolve. if (_this._promise !== null) { // If so check whether there are no pending macrotasks before resolving. // Do this check in the next tick so that ngZone gets a chance to update the state of // pending macrotasks. scheduleMicroTask(function () { if (!ngZone.hasPendingMacrotasks) { if (_this._promise !== null) { _this._resolve(true); _this._resolve = null; _this._promise = null; } } }); } } }); _this._onErrorSubscription = ngZone.onError.subscribe({ next: function (error) { throw error; } }); }); } } ComponentFixture.prototype._tick = function (checkNoChanges) { this.changeDetectorRef.detectChanges(); if (checkNoChanges) { this.checkNoChanges(); } }; /** * Trigger a change detection cycle for the component. */ ComponentFixture.prototype.detectChanges = function (checkNoChanges) { var _this = this; if (checkNoChanges === void 0) { checkNoChanges = true; } if (this.ngZone != null) { // Run the change detection inside the NgZone so that any async tasks as part of the change // detection are captured by the zone and can be waited for in isStable. this.ngZone.run(function () { _this._tick(checkNoChanges); }); } else { // Running without zone. Just do the change detection. this._tick(checkNoChanges); } }; /** * Do a change detection run to make sure there were no changes. */ ComponentFixture.prototype.checkNoChanges = function () { this.changeDetectorRef.checkNoChanges(); }; /** * Set whether the fixture should autodetect changes. * * Also runs detectChanges once so that any existing change is detected. */ ComponentFixture.prototype.autoDetectChanges = function (autoDetect) { if (autoDetect === void 0) { autoDetect = true; } if (this.ngZone == null) { throw new Error('Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set'); } this._autoDetect = autoDetect; this.detectChanges(); }; /** * Return whether the fixture is currently stable or has async tasks that have not been completed * yet. */ ComponentFixture.prototype.isStable = function () { return this._isStable && !this.ngZone.hasPendingMacrotasks; }; /** * Get a promise that resolves when the fixture is stable. * * This can be used to resume testing after events have triggered asynchronous activity or * asynchronous change detection. */ ComponentFixture.prototype.whenStable = function () { var _this = this; if (this.isStable()) { return Promise.resolve(false); } else if (this._promise !== null) { return this._promise; } else { this._promise = new Promise(function (res) { _this._resolve = res; }); return this._promise; } }; ComponentFixture.prototype._getRenderer = function () { if (this._renderer === undefined) { this._renderer = this.componentRef.injector.get(core.RendererFactory2, null); } return this._renderer; }; /** * Get a promise that resolves when the ui state is stable following animations. */ ComponentFixture.prototype.whenRenderingDone = function () { var renderer = this._getRenderer(); if (renderer && renderer.whenRenderingDone) { return renderer.whenRenderingDone(); } return this.whenStable(); }; /** * Trigger component destruction. */ ComponentFixture.prototype.destroy = function () { if (!this._isDestroyed) { this.componentRef.destroy(); if (this._onUnstableSubscription != null) { this._onUnstableSubscription.unsubscribe(); this._onUnstableSubscription = null; } if (this._onStableSubscription != null) { this._onStableSubscription.unsubscribe(); this._onStableSubscription = null; } if (this._onMicrotaskEmptySubscription != null) { this._onMicrotaskEmptySubscription.unsubscribe(); this._onMicrotaskEmptySubscription = null; } if (this._onErrorSubscription != null) { this._onErrorSubscription.unsubscribe(); this._onErrorSubscription = null; } this._isDestroyed = true; } }; return ComponentFixture; }()); function scheduleMicroTask(fn) { Zone.current.scheduleMicroTask('scheduleMicrotask', fn); } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * fakeAsync has been moved to zone.js * this file is for fallback in case old version of zone.js is used */ var _Zone = typeof Zone !== 'undefined' ? Zone : null; var FakeAsyncTestZoneSpec = _Zone && _Zone['FakeAsyncTestZoneSpec']; var ProxyZoneSpec = _Zone && _Zone['ProxyZoneSpec']; var _fakeAsyncTestZoneSpec = null; /** * Clears out the shared fake async zone for a test. * To be called in a global `beforeEach`. * * @publicApi */ function resetFakeAsyncZoneFallback() { _fakeAsyncTestZoneSpec = null; // in node.js testing we may not have ProxyZoneSpec in which case there is nothing to reset. ProxyZoneSpec && ProxyZoneSpec.assertPresent().resetDelegate(); } var _inFakeAsyncCall = false; /** * Wraps a function to be executed in the fakeAsync zone: * - microtasks are manually executed by calling `flushMicrotasks()`, * - timers are synchronous, `tick()` simulates the asynchronous passage of time. * * If there are any pending timers at the end of the function, an exception will be thrown. * * Can be used to wrap inject() calls. * * @usageNotes * ### Example * * {@example core/testing/ts/fake_async.ts region='basic'} * * @param fn * @returns The function wrapped to be executed in the fakeAsync zone * * @publicApi */ function fakeAsyncFallback(fn) { // Not using an arrow function to preserve context passed from call site return function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var proxyZoneSpec = ProxyZoneSpec.assertPresent(); if (_inFakeAsyncCall) { throw new Error('fakeAsync() calls can not be nested'); } _inFakeAsyncCall = true; try { if (!_fakeAsyncTestZoneSpec) { if (proxyZoneSpec.getDelegate() instanceof FakeAsyncTestZoneSpec) { throw new Error('fakeAsync() calls can not be nested'); } _fakeAsyncTestZoneSpec = new FakeAsyncTestZoneSpec(); } var res = void 0; var lastProxyZoneSpec = proxyZoneSpec.getDelegate(); proxyZoneSpec.setDelegate(_fakeAsyncTestZoneSpec); try { res = fn.apply(this, args); flushMicrotasksFallback(); } finally { proxyZoneSpec.setDelegate(lastProxyZoneSpec); } if (_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length > 0) { throw new Error(_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length + " " + "periodic timer(s) still in the queue."); } if (_fakeAsyncTestZoneSpec.pendingTimers.length > 0) { throw new Error(_fakeAsyncTestZoneSpec.pendingTimers.length + " timer(s) still in the queue."); } return res; } finally { _inFakeAsyncCall = false; resetFakeAsyncZoneFallback(); } }; } function _getFakeAsyncZoneSpec() { if (_fakeAsyncTestZoneSpec == null) { throw new Error('The code should be running in the fakeAsync zone to call this function'); } return _fakeAsyncTestZoneSpec; } /** * Simulates the asynchronous passage of time for the timers in the fakeAsync zone. * * The microtasks queue is drained at the very start of this function and after any timer callback * has been executed. * * @usageNotes * ### Example * * {@example core/testing/ts/fake_async.ts region='basic'} * * @publicApi */ function tickFallback(millis, tickOptions) { if (millis === void 0) { millis = 0; } if (tickOptions === void 0) { tickOptions = { processNewMacroTasksSynchronously: true }; } _getFakeAsyncZoneSpec().tick(millis, null, tickOptions); } /** * Simulates the asynchronous passage of time for the timers in the fakeAsync zone by * draining the macrotask queue until it is empty. The returned value is the milliseconds * of time that would have been elapsed. * * @param maxTurns * @returns The simulated time elapsed, in millis. * * @publicApi */ function flushFallback(maxTurns) { return _getFakeAsyncZoneSpec().flush(maxTurns); } /** * Discard all remaining periodic tasks. * * @publicApi */ function discardPeriodicTasksFallback() { var zoneSpec = _getFakeAsyncZoneSpec(); zoneSpec.pendingPeriodicTimers.length = 0; } /** * Flush any pending microtasks. * * @publicApi */ function flushMicrotasksFallback() { _getFakeAsyncZoneSpec().flushMicrotasks(); } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ var _Zone$1 = typeof Zone !== 'undefined' ? Zone : null; var fakeAsyncTestModule = _Zone$1 && _Zone$1[_Zone$1.__symbol__('fakeAsyncTest')]; /** * Clears out the shared fake async zone for a test. * To be called in a global `beforeEach`. * * @publicApi */ function resetFakeAsyncZone() { if (fakeAsyncTestModule) { return fakeAsyncTestModule.resetFakeAsyncZone(); } else { return resetFakeAsyncZoneFallback(); } } /** * Wraps a function to be executed in the fakeAsync zone: * - microtasks are manually executed by calling `flushMicrotasks()`, * - timers are synchronous, `tick()` simulates the asynchronous passage of time. * * If there are any pending timers at the end of the function, an exception will be thrown. * * Can be used to wrap inject() calls. * * @usageNotes * ### Example * * {@example core/testing/ts/fake_async.ts region='basic'} * * @param fn * @returns The function wrapped to be executed in the fakeAsync zone * * @publicApi */ function fakeAsync(fn) { if (fakeAsyncTestModule) { return fakeAsyncTestModule.fakeAsync(fn); } else { return fakeAsyncFallback(fn); } } /** * Simulates the asynchronous passage of time for the timers in the fakeAsync zone. * * The microtasks queue is drained at the very start of this function and after any timer callback * has been executed. * * @usageNotes * ### Example * * {@example core/testing/ts/fake_async.ts region='basic'} * * @param millis, the number of millisecond to advance the virtual timer * @param tickOptions, the options of tick with a flag called * processNewMacroTasksSynchronously, whether to invoke the new macroTasks, by default is * false, means the new macroTasks will be invoked * * For example, * * it ('test with nested setTimeout', fakeAsync(() => { * let nestedTimeoutInvoked = false; * function funcWithNestedTimeout() { * setTimeout(() => { * nestedTimeoutInvoked = true; * }); * }; * setTimeout(funcWithNestedTimeout); * tick(); * expect(nestedTimeoutInvoked).toBe(true); * })); * * in this case, we have a nested timeout (new macroTask), when we tick, both the * funcWithNestedTimeout and the nested timeout both will be invoked. * * it ('test with nested setTimeout', fakeAsync(() => { * let nestedTimeoutInvoked = false; * function funcWithNestedTimeout() { * setTimeout(() => { * nestedTimeoutInvoked = true; * }); * }; * setTimeout(funcWithNestedTimeout); * tick(0, {processNewMacroTasksSynchronously: false}); * expect(nestedTimeoutInvoked).toBe(false); * })); * * if we pass the tickOptions with processNewMacroTasksSynchronously to be false, the nested timeout * will not be invoked. * * * @publicApi */ function tick(millis, tickOptions) { if (millis === void 0) { millis = 0; } if (tickOptions === void 0) { tickOptions = { processNewMacroTasksSynchronously: true }; } if (fakeAsyncTestModule) { return fakeAsyncTestModule.tick(millis, tickOptions); } else { return tickFallback(millis, tickOptions); } } /** * Simulates the asynchronous passage of time for the timers in the fakeAsync zone by * draining the macrotask queue until it is empty. The returned value is the milliseconds * of time that would have been elapsed. * * @param maxTurns * @returns The simulated time elapsed, in millis. * * @publicApi */ function flush(maxTurns) { if (fakeAsyncTestModule) { return fakeAsyncTestModule.flush(maxTurns); } else { return flushFallback(maxTurns); } } /** * Discard all remaining periodic tasks. * * @publicApi */ function discardPeriodicTasks() { if (fakeAsyncTestModule) { return fakeAsyncTestModule.discardPeriodicTasks(); } else { discardPeriodicTasksFallback(); } } /** * Flush any pending microtasks. * * @publicApi */ function flushMicrotasks() { if (fakeAsyncTestModule) { return fakeAsyncTestModule.flushMicrotasks(); } else { return flushMicrotasksFallback(); } } /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; } function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __param(paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } } function __metadata(metadataKey, metadataValue) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); } function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { 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) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function __exportStar(m, exports) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } function __values(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } function __spreadArrays() { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; }; function __await(v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } function __asyncGenerator(thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } } function __asyncDelegator(o) { var i, p; return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; 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; } } function __asyncValues(o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; 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); 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); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } } function __makeTemplateObject(cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; }; function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; result.default = mod; return result; } function __importDefault(mod) { return (mod && mod.__esModule) ? mod : { default: mod }; } function __classPrivateFieldGet(receiver, privateMap) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return privateMap.get(receiver); } function __classPrivateFieldSet(receiver, privateMap, value) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to set private field on non-instance"); } privateMap.set(receiver, value); return value; } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * Injectable completer that allows signaling completion of an asynchronous test. Used internally. */ var AsyncTestCompleter = /** @class */ (function () { function AsyncTestCompleter() { var _this = this; this._promise = new Promise(function (res, rej) { _this._resolve = res; _this._reject = rej; }); } AsyncTestCompleter.prototype.done = function (value) { this._resolve(value); }; AsyncTestCompleter.prototype.fail = function (error, stackTrace) { this._reject(error); }; Object.defineProperty(AsyncTestCompleter.prototype, "promise", { get: function () { return this._promise; }, enumerable: true, configurable: true }); return AsyncTestCompleter; }()); /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ /** * Used to resolve resource URLs on `@Component` when used with JIT compilation. * * Example: * ``` * @Component({ * selector: 'my-comp', * templateUrl: 'my-comp.html', // This requires asynchronous resolution * }) * class MyComponent{ * } * * // Calling `renderComponent` will fail because `renderComponent` is a synchronous process * // and `MyComponent`'s `@Component.templateUrl` needs to be resolved asynchronously. * * // Calling `resolveComponentResources()` will resolve `@Component.templateUrl` into * // `@Component.template`, which allows `renderComponent` to proceed in a synchronous manner. * * // Use browser's `fetch()` function as the default resource resolution strategy. * resolveComponentResources(fetch).then(() => { * // After resolution all URLs have been converted into `template` strings. * renderComponent(MyComponent); * }); * * ``` * * NOTE: In AOT the resolution happens during compilation, and so there should be no need * to call this method outside JIT mode. * * @param resourceResolver a function which is responsible for returning a `Promise` to the * contents of the resolved URL. Browser's `fetch()` method is a good default implementation. */ function resolveComponentResources(resourceResolver) { // Store all promises which are fetching the resources. var componentResolved = []; // Cache so that we don't fetch the same resource more than once. var urlMap = new Map(); function cachedResourceResolve(url) { var promise = urlMap.get(url); if (!promise) { var resp = resourceResolver(url); urlMap.set(url, promise = resp.then(unwrapResponse)); } return promise; } componentResourceResolutionQueue.forEach(function (component, type) { var promises = []; if (component.templateUrl) { promises.push(cachedResourceResolve(component.templateUrl).then(function (template) { component.template = template; })); } var styleUrls = component.styleUrls; var styles = component.styles || (component.styles = []); var styleOffset = component.styles.length; styleUrls && styleUrls.forEach(function (styleUrl, index) { styles.push(''); // pre-allocate array. promises.push(cachedResourceResolve(styleUrl).then(function (style) { styles[styleOffset + index] = style; styleUrls.splice(styleUrls.indexOf(styleUrl), 1); if (styleUrls.length == 0) { component.styleUrls = undefined; } })); }); var fullyResolved = Promise.all(promises).then(function () { return componentDefResolved(type); }); componentResolved.push(fullyResolved); }); clearResolutionOfComponentResourcesQueue(); return Promise.all(componentResolved).then(function () { return undefined; }); } var componentResourceResolutionQueue = new Map(); // Track when existing ɵcmp for a Type is waiting on resources. var componentDefPendingResolution = new Set(); function maybeQueueResolutionOfComponentResources(type, metadata) { if (componentNeedsResolution(metadata)) { componentResourceResolutionQueue.set(type, metadata); componentDefPendingResolution.add(type); } } function isComponentDefPendingResolution(type) { return componentDefPendingResolution.has(type); } function componentNeedsResolution(component) { return !!((component.templateUrl && !component.hasOwnProperty('template')) || component.styleUrls && component.styleUrls.length); } function clearResolutionOfComponentResourcesQueue() { var old = componentResourceResolutionQueue; componentResourceResolutionQueue = new Map(); return old; } function restoreComponentResolutionQueue(queue) { componentDefPendingResolution.clear(); queue.forEach(function (_, type) { return componentDefPendingResolution.add(type); }); componentResourceResolutionQueue = queue; } function isComponentResourceResolutionQueueEmpty() { return componentResourceResolutionQueue.size === 0; } function unwrapResponse(response) { return typeof response == 'string' ? response : response.text(); } function componentDefResolved(type) { componentDefPendingResolution.delete(type); } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ var _nextReferenceId = 0; var MetadataOverrider = /** @class */ (function () { function MetadataOverrider() { this._references = new Map(); } /** * Creates a new instance for the given metadata class * based on an old instance and overrides. */ MetadataOverrider.prototype.overrideMetadata = function (metadataClass, oldMetadata, override) { var props = {}; if (oldMetadata) { _valueProps(oldMetadata).forEach(function (prop) { return props[prop] = oldMetadata[prop]; }); } if (override.set) { if (override.remove || override.add) { throw new Error("Cannot set and add/remove " + core.ɵstringify(metadataClass) + " at the same time!"); } setMetadata(props, override.set); } if (override.remove) { removeMetadata(props, override.remove, this._references); } if (override.add) { addMetadata(props, override.add); } return new metadataClass(props); }; return MetadataOverrider; }()); function removeMetadata(metadata, remove, references) { var removeObjects = new Set(); var _loop_1 = function (prop) { var removeValue = remove[prop]; if (Array.isArray(removeValue)) { removeValue.forEach(function (value) { removeObjects.add(_propHashKey(prop, value, references)); }); } else { removeObjects.add(_propHashKey(prop, removeValue, references)); } }; for (var prop in remove) { _loop_1(prop); } var _loop_2 = function (prop) { var propValue = metadata[prop]; if (Array.isArray(propValue)) { metadata[prop] = propValue.filter(function (value) { return !removeObjects.has(_propHashKey(prop, value, references)); }); } else { if (removeObjects.has(_propHashKey(prop, propValue, references))) { metadata[prop] = undefined; } } }; for (var prop in metadata) { _loop_2(prop); } } function addMetadata(metadata, add) { for (var prop in add) { var addValue = add[prop]; var propValue = metadata[prop]; if (propValue != null && Array.isArray(propValue)) { metadata[prop] = propValue.concat(addValue); } else { metadata[prop] = addValue; } } } function setMetadata(metadata, set) { for (var prop in set) { metadata[prop] = set[prop]; } } function _propHashKey(propName, propValue, references) { var replacer = function (key, value) { if (typeof value === 'function') { value = _serializeReference(value, references); } return value; }; return propName + ":" + JSON.stringify(propValue, replacer); } function _serializeReference(ref, references) { var id = references.get(ref); if (!id) { id = "" + core.ɵstringify(ref) + _nextReferenceId++; references.set(ref, id); } return id; } function _valueProps(obj) { var props = []; // regular public props Object.keys(obj).forEach(function (prop) { if (!prop.startsWith('_')) { props.push(prop); } }); // getters var proto = obj; while (proto = Object.getPrototypeOf(proto)) { Object.keys(proto).forEach(function (protoProp) { var desc = Object.getOwnPropertyDescriptor(proto, protoProp); if (!protoProp.startsWith('_') && desc && 'get' in desc) { props.push(protoProp); } }); } return props; } /** * @license * Copyright Google Inc. All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ var reflection = new core.ɵReflectionCapabilities(); /** * Allows to override ivy metadata for tests (via the `TestBed`). */ var OverrideResolver = /** @class */ (function () { function OverrideResolver() { this.overrides = new Map(); this.resolved = new Map(); } OverrideResolver.prototype.addOverride = function (type, override) { var overrides = this.overrides.get(type) || []; overrides.push(override); this.overrides.set(type, overrides); this.resolved.delete(type); }; OverrideResolver.prototype.setOverrides = function (overrides) { var _this = this; this.overrides.clear(); overrides.forEach(function (_a) { var _b = __read(_a, 2), type = _b[0], override = _b[1]; _this.addOverride(type, override); }); }; OverrideResolver.prototype.getAnnotation = function (type) { var annotations = reflection.annotations(type); // Try to find the nearest known Type annotation and make sure that this annotation is an // instance of the type we are looking for, so we can use it for resolution. Note: there might // be multiple known annotations found due to the fact that Components can extend Directives (so // both Directive and Component annotations would be present), so we always check if the known // annotation has the right type. for (var i = annotations.length - 1; i >= 0; i--) { var annotation = annotations[i]; var isKnownType = annotation instanceof core.Directive || annotation instanceof core.Component || annotation instanceof core.Pipe || annotation instanceof core.NgModule; if (isKnownType) { return annotation instanceof this.type ? annotation : null; } } return null; }; OverrideResolver.prototype.resolve = function (type) { var _this = this; var resolved = this.resolved.get(type) || null; if (!resolved) { resolved = this.getAnnotation(type); if (resolved) { var overrides = this.overrides.get(type); if (overrides) { var overrider_1 = new MetadataOverrider(); overrides.forEach(function (override) { resolved = overrider_1.overrideMetadata(_this.type, resolved, override); }); } } this.resolved.set(type, resolved); } return resolved; }; return OverrideResolver; }()); var DirectiveResolver = /** @class */ (function (_super) { __extends(DirectiveResolver, _super); function DirectiveResolver() { return _super !== null && _super.apply(this, arguments) || thi