testing.js 109 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695
  1. /**
  2. * @license Angular v8.1.0
  3. * (c) 2010-2019 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import { RendererFactory2, getDebugNode, InjectionToken, ɵstringify, ɵReflectionCapabilities, Directive, Component, Pipe, NgModule, COMPILER_OPTIONS, ɵcompileNgModuleDefs, ɵNgModuleFactory, ɵgetInjectableDef, ɵNG_COMPONENT_DEF, ɵRender3NgModuleRef, LOCALE_ID, ɵDEFAULT_LOCALE_ID, ɵsetLocaleId, ApplicationInitStatus, ɵRender3ComponentFactory, ɵcompileComponent, ɵNG_DIRECTIVE_DEF, ɵcompileDirective, ɵNG_PIPE_DEF, ɵcompilePipe, ɵpatchComponentDefWithScope, ɵNG_INJECTOR_DEF, ɵNG_MODULE_DEF, NgZone, Compiler, ɵtransitiveScopesFor, ModuleWithComponentFactories, ɵresetCompiledComponents, Injector, InjectFlags, ɵflushModuleScopingQueueAsMuchAsPossible, Injectable, ɵclearOverrides, ɵoverrideComponentView, ɵAPP_ROOT, ɵoverrideProvider, ɵivyEnabled, Optional, SkipSelf } from '@angular/core';
  7. import { __read, __extends, __spread, __awaiter, __generator, __values, __decorate } from 'tslib';
  8. import { ResourceLoader } from '@angular/compiler';
  9. /**
  10. * @license
  11. * Copyright Google Inc. All Rights Reserved.
  12. *
  13. * Use of this source code is governed by an MIT-style license that can be
  14. * found in the LICENSE file at https://angular.io/license
  15. */
  16. var _global = (typeof window === 'undefined' ? global : window);
  17. /**
  18. * Wraps a test function in an asynchronous test zone. The test will automatically
  19. * complete when all asynchronous calls within this zone are done. Can be used
  20. * to wrap an {@link inject} call.
  21. *
  22. * Example:
  23. *
  24. * ```
  25. * it('...', async(inject([AClass], (object) => {
  26. * object.doSomething.then(() => {
  27. * expect(...);
  28. * })
  29. * });
  30. * ```
  31. *
  32. *
  33. */
  34. function asyncFallback(fn) {
  35. // If we're running using the Jasmine test framework, adapt to call the 'done'
  36. // function when asynchronous activity is finished.
  37. if (_global.jasmine) {
  38. // Not using an arrow function to preserve context passed from call site
  39. return function (done) {
  40. if (!done) {
  41. // if we run beforeEach in @angular/core/testing/testing_internal then we get no done
  42. // fake it here and assume sync.
  43. done = function () { };
  44. done.fail = function (e) { throw e; };
  45. }
  46. runInTestZone(fn, this, done, function (err) {
  47. if (typeof err === 'string') {
  48. return done.fail(new Error(err));
  49. }
  50. else {
  51. done.fail(err);
  52. }
  53. });
  54. };
  55. }
  56. // Otherwise, return a promise which will resolve when asynchronous activity
  57. // is finished. This will be correctly consumed by the Mocha framework with
  58. // it('...', async(myFn)); or can be used in a custom framework.
  59. // Not using an arrow function to preserve context passed from call site
  60. return function () {
  61. var _this = this;
  62. return new Promise(function (finishCallback, failCallback) {
  63. runInTestZone(fn, _this, finishCallback, failCallback);
  64. });
  65. };
  66. }
  67. function runInTestZone(fn, context, finishCallback, failCallback) {
  68. var currentZone = Zone.current;
  69. var AsyncTestZoneSpec = Zone['AsyncTestZoneSpec'];
  70. if (AsyncTestZoneSpec === undefined) {
  71. throw new Error('AsyncTestZoneSpec is needed for the async() test helper but could not be found. ' +
  72. 'Please make sure that your environment includes zone.js/dist/async-test.js');
  73. }
  74. var ProxyZoneSpec = Zone['ProxyZoneSpec'];
  75. if (ProxyZoneSpec === undefined) {
  76. throw new Error('ProxyZoneSpec is needed for the async() test helper but could not be found. ' +
  77. 'Please make sure that your environment includes zone.js/dist/proxy.js');
  78. }
  79. var proxyZoneSpec = ProxyZoneSpec.get();
  80. ProxyZoneSpec.assertPresent();
  81. // We need to create the AsyncTestZoneSpec outside the ProxyZone.
  82. // If we do it in ProxyZone then we will get to infinite recursion.
  83. var proxyZone = Zone.current.getZoneWith('ProxyZoneSpec');
  84. var previousDelegate = proxyZoneSpec.getDelegate();
  85. proxyZone.parent.run(function () {
  86. var testZoneSpec = new AsyncTestZoneSpec(function () {
  87. // Need to restore the original zone.
  88. currentZone.run(function () {
  89. if (proxyZoneSpec.getDelegate() == testZoneSpec) {
  90. // Only reset the zone spec if it's sill this one. Otherwise, assume it's OK.
  91. proxyZoneSpec.setDelegate(previousDelegate);
  92. }
  93. finishCallback();
  94. });
  95. }, function (error) {
  96. // Need to restore the original zone.
  97. currentZone.run(function () {
  98. if (proxyZoneSpec.getDelegate() == testZoneSpec) {
  99. // Only reset the zone spec if it's sill this one. Otherwise, assume it's OK.
  100. proxyZoneSpec.setDelegate(previousDelegate);
  101. }
  102. failCallback(error);
  103. });
  104. }, 'test');
  105. proxyZoneSpec.setDelegate(testZoneSpec);
  106. });
  107. return Zone.current.runGuarded(fn, context);
  108. }
  109. /**
  110. * @license
  111. * Copyright Google Inc. All Rights Reserved.
  112. *
  113. * Use of this source code is governed by an MIT-style license that can be
  114. * found in the LICENSE file at https://angular.io/license
  115. */
  116. /**
  117. * Wraps a test function in an asynchronous test zone. The test will automatically
  118. * complete when all asynchronous calls within this zone are done. Can be used
  119. * to wrap an {@link inject} call.
  120. *
  121. * Example:
  122. *
  123. * ```
  124. * it('...', async(inject([AClass], (object) => {
  125. * object.doSomething.then(() => {
  126. * expect(...);
  127. * })
  128. * });
  129. * ```
  130. *
  131. * @publicApi
  132. */
  133. function async(fn) {
  134. var _Zone = typeof Zone !== 'undefined' ? Zone : null;
  135. if (!_Zone) {
  136. return function () {
  137. return Promise.reject('Zone is needed for the async() test helper but could not be found. ' +
  138. 'Please make sure that your environment includes zone.js/dist/zone.js');
  139. };
  140. }
  141. var asyncTest = _Zone && _Zone[_Zone.__symbol__('asyncTest')];
  142. if (typeof asyncTest === 'function') {
  143. return asyncTest(fn);
  144. }
  145. // not using new version of zone.js
  146. // TODO @JiaLiPassion, remove this after all library updated to
  147. // newest version of zone.js(0.8.25)
  148. return asyncFallback(fn);
  149. }
  150. /**
  151. * @license
  152. * Copyright Google Inc. All Rights Reserved.
  153. *
  154. * Use of this source code is governed by an MIT-style license that can be
  155. * found in the LICENSE file at https://angular.io/license
  156. */
  157. /**
  158. * Fixture for debugging and testing a component.
  159. *
  160. * @publicApi
  161. */
  162. var ComponentFixture = /** @class */ (function () {
  163. function ComponentFixture(componentRef, ngZone, _autoDetect) {
  164. var _this = this;
  165. this.componentRef = componentRef;
  166. this.ngZone = ngZone;
  167. this._autoDetect = _autoDetect;
  168. this._isStable = true;
  169. this._isDestroyed = false;
  170. this._resolve = null;
  171. this._promise = null;
  172. this._onUnstableSubscription = null;
  173. this._onStableSubscription = null;
  174. this._onMicrotaskEmptySubscription = null;
  175. this._onErrorSubscription = null;
  176. this.changeDetectorRef = componentRef.changeDetectorRef;
  177. this.elementRef = componentRef.location;
  178. this.debugElement = getDebugNode(this.elementRef.nativeElement);
  179. this.componentInstance = componentRef.instance;
  180. this.nativeElement = this.elementRef.nativeElement;
  181. this.componentRef = componentRef;
  182. this.ngZone = ngZone;
  183. if (ngZone) {
  184. // Create subscriptions outside the NgZone so that the callbacks run oustide
  185. // of NgZone.
  186. ngZone.runOutsideAngular(function () {
  187. _this._onUnstableSubscription =
  188. ngZone.onUnstable.subscribe({ next: function () { _this._isStable = false; } });
  189. _this._onMicrotaskEmptySubscription = ngZone.onMicrotaskEmpty.subscribe({
  190. next: function () {
  191. if (_this._autoDetect) {
  192. // Do a change detection run with checkNoChanges set to true to check
  193. // there are no changes on the second run.
  194. _this.detectChanges(true);
  195. }
  196. }
  197. });
  198. _this._onStableSubscription = ngZone.onStable.subscribe({
  199. next: function () {
  200. _this._isStable = true;
  201. // Check whether there is a pending whenStable() completer to resolve.
  202. if (_this._promise !== null) {
  203. // If so check whether there are no pending macrotasks before resolving.
  204. // Do this check in the next tick so that ngZone gets a chance to update the state of
  205. // pending macrotasks.
  206. scheduleMicroTask(function () {
  207. if (!ngZone.hasPendingMacrotasks) {
  208. if (_this._promise !== null) {
  209. _this._resolve(true);
  210. _this._resolve = null;
  211. _this._promise = null;
  212. }
  213. }
  214. });
  215. }
  216. }
  217. });
  218. _this._onErrorSubscription =
  219. ngZone.onError.subscribe({ next: function (error) { throw error; } });
  220. });
  221. }
  222. }
  223. ComponentFixture.prototype._tick = function (checkNoChanges) {
  224. this.changeDetectorRef.detectChanges();
  225. if (checkNoChanges) {
  226. this.checkNoChanges();
  227. }
  228. };
  229. /**
  230. * Trigger a change detection cycle for the component.
  231. */
  232. ComponentFixture.prototype.detectChanges = function (checkNoChanges) {
  233. var _this = this;
  234. if (checkNoChanges === void 0) { checkNoChanges = true; }
  235. if (this.ngZone != null) {
  236. // Run the change detection inside the NgZone so that any async tasks as part of the change
  237. // detection are captured by the zone and can be waited for in isStable.
  238. this.ngZone.run(function () { _this._tick(checkNoChanges); });
  239. }
  240. else {
  241. // Running without zone. Just do the change detection.
  242. this._tick(checkNoChanges);
  243. }
  244. };
  245. /**
  246. * Do a change detection run to make sure there were no changes.
  247. */
  248. ComponentFixture.prototype.checkNoChanges = function () { this.changeDetectorRef.checkNoChanges(); };
  249. /**
  250. * Set whether the fixture should autodetect changes.
  251. *
  252. * Also runs detectChanges once so that any existing change is detected.
  253. */
  254. ComponentFixture.prototype.autoDetectChanges = function (autoDetect) {
  255. if (autoDetect === void 0) { autoDetect = true; }
  256. if (this.ngZone == null) {
  257. throw new Error('Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set');
  258. }
  259. this._autoDetect = autoDetect;
  260. this.detectChanges();
  261. };
  262. /**
  263. * Return whether the fixture is currently stable or has async tasks that have not been completed
  264. * yet.
  265. */
  266. ComponentFixture.prototype.isStable = function () { return this._isStable && !this.ngZone.hasPendingMacrotasks; };
  267. /**
  268. * Get a promise that resolves when the fixture is stable.
  269. *
  270. * This can be used to resume testing after events have triggered asynchronous activity or
  271. * asynchronous change detection.
  272. */
  273. ComponentFixture.prototype.whenStable = function () {
  274. var _this = this;
  275. if (this.isStable()) {
  276. return Promise.resolve(false);
  277. }
  278. else if (this._promise !== null) {
  279. return this._promise;
  280. }
  281. else {
  282. this._promise = new Promise(function (res) { _this._resolve = res; });
  283. return this._promise;
  284. }
  285. };
  286. ComponentFixture.prototype._getRenderer = function () {
  287. if (this._renderer === undefined) {
  288. this._renderer = this.componentRef.injector.get(RendererFactory2, null);
  289. }
  290. return this._renderer;
  291. };
  292. /**
  293. * Get a promise that resolves when the ui state is stable following animations.
  294. */
  295. ComponentFixture.prototype.whenRenderingDone = function () {
  296. var renderer = this._getRenderer();
  297. if (renderer && renderer.whenRenderingDone) {
  298. return renderer.whenRenderingDone();
  299. }
  300. return this.whenStable();
  301. };
  302. /**
  303. * Trigger component destruction.
  304. */
  305. ComponentFixture.prototype.destroy = function () {
  306. if (!this._isDestroyed) {
  307. this.componentRef.destroy();
  308. if (this._onUnstableSubscription != null) {
  309. this._onUnstableSubscription.unsubscribe();
  310. this._onUnstableSubscription = null;
  311. }
  312. if (this._onStableSubscription != null) {
  313. this._onStableSubscription.unsubscribe();
  314. this._onStableSubscription = null;
  315. }
  316. if (this._onMicrotaskEmptySubscription != null) {
  317. this._onMicrotaskEmptySubscription.unsubscribe();
  318. this._onMicrotaskEmptySubscription = null;
  319. }
  320. if (this._onErrorSubscription != null) {
  321. this._onErrorSubscription.unsubscribe();
  322. this._onErrorSubscription = null;
  323. }
  324. this._isDestroyed = true;
  325. }
  326. };
  327. return ComponentFixture;
  328. }());
  329. function scheduleMicroTask(fn) {
  330. Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
  331. }
  332. /**
  333. * @license
  334. * Copyright Google Inc. All Rights Reserved.
  335. *
  336. * Use of this source code is governed by an MIT-style license that can be
  337. * found in the LICENSE file at https://angular.io/license
  338. */
  339. /**
  340. * fakeAsync has been moved to zone.js
  341. * this file is for fallback in case old version of zone.js is used
  342. */
  343. var _Zone = typeof Zone !== 'undefined' ? Zone : null;
  344. var FakeAsyncTestZoneSpec = _Zone && _Zone['FakeAsyncTestZoneSpec'];
  345. var ProxyZoneSpec = _Zone && _Zone['ProxyZoneSpec'];
  346. var _fakeAsyncTestZoneSpec = null;
  347. /**
  348. * Clears out the shared fake async zone for a test.
  349. * To be called in a global `beforeEach`.
  350. *
  351. * @publicApi
  352. */
  353. function resetFakeAsyncZoneFallback() {
  354. _fakeAsyncTestZoneSpec = null;
  355. // in node.js testing we may not have ProxyZoneSpec in which case there is nothing to reset.
  356. ProxyZoneSpec && ProxyZoneSpec.assertPresent().resetDelegate();
  357. }
  358. var _inFakeAsyncCall = false;
  359. /**
  360. * Wraps a function to be executed in the fakeAsync zone:
  361. * - microtasks are manually executed by calling `flushMicrotasks()`,
  362. * - timers are synchronous, `tick()` simulates the asynchronous passage of time.
  363. *
  364. * If there are any pending timers at the end of the function, an exception will be thrown.
  365. *
  366. * Can be used to wrap inject() calls.
  367. *
  368. * @usageNotes
  369. * ### Example
  370. *
  371. * {@example core/testing/ts/fake_async.ts region='basic'}
  372. *
  373. * @param fn
  374. * @returns The function wrapped to be executed in the fakeAsync zone
  375. *
  376. * @publicApi
  377. */
  378. function fakeAsyncFallback(fn) {
  379. // Not using an arrow function to preserve context passed from call site
  380. return function () {
  381. var args = [];
  382. for (var _i = 0; _i < arguments.length; _i++) {
  383. args[_i] = arguments[_i];
  384. }
  385. var proxyZoneSpec = ProxyZoneSpec.assertPresent();
  386. if (_inFakeAsyncCall) {
  387. throw new Error('fakeAsync() calls can not be nested');
  388. }
  389. _inFakeAsyncCall = true;
  390. try {
  391. if (!_fakeAsyncTestZoneSpec) {
  392. if (proxyZoneSpec.getDelegate() instanceof FakeAsyncTestZoneSpec) {
  393. throw new Error('fakeAsync() calls can not be nested');
  394. }
  395. _fakeAsyncTestZoneSpec = new FakeAsyncTestZoneSpec();
  396. }
  397. var res = void 0;
  398. var lastProxyZoneSpec = proxyZoneSpec.getDelegate();
  399. proxyZoneSpec.setDelegate(_fakeAsyncTestZoneSpec);
  400. try {
  401. res = fn.apply(this, args);
  402. flushMicrotasksFallback();
  403. }
  404. finally {
  405. proxyZoneSpec.setDelegate(lastProxyZoneSpec);
  406. }
  407. if (_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length > 0) {
  408. throw new Error(_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length + " " +
  409. "periodic timer(s) still in the queue.");
  410. }
  411. if (_fakeAsyncTestZoneSpec.pendingTimers.length > 0) {
  412. throw new Error(_fakeAsyncTestZoneSpec.pendingTimers.length + " timer(s) still in the queue.");
  413. }
  414. return res;
  415. }
  416. finally {
  417. _inFakeAsyncCall = false;
  418. resetFakeAsyncZoneFallback();
  419. }
  420. };
  421. }
  422. function _getFakeAsyncZoneSpec() {
  423. if (_fakeAsyncTestZoneSpec == null) {
  424. throw new Error('The code should be running in the fakeAsync zone to call this function');
  425. }
  426. return _fakeAsyncTestZoneSpec;
  427. }
  428. /**
  429. * Simulates the asynchronous passage of time for the timers in the fakeAsync zone.
  430. *
  431. * The microtasks queue is drained at the very start of this function and after any timer callback
  432. * has been executed.
  433. *
  434. * @usageNotes
  435. * ### Example
  436. *
  437. * {@example core/testing/ts/fake_async.ts region='basic'}
  438. *
  439. * @publicApi
  440. */
  441. function tickFallback(millis) {
  442. if (millis === void 0) { millis = 0; }
  443. _getFakeAsyncZoneSpec().tick(millis);
  444. }
  445. /**
  446. * Simulates the asynchronous passage of time for the timers in the fakeAsync zone by
  447. * draining the macrotask queue until it is empty. The returned value is the milliseconds
  448. * of time that would have been elapsed.
  449. *
  450. * @param maxTurns
  451. * @returns The simulated time elapsed, in millis.
  452. *
  453. * @publicApi
  454. */
  455. function flushFallback(maxTurns) {
  456. return _getFakeAsyncZoneSpec().flush(maxTurns);
  457. }
  458. /**
  459. * Discard all remaining periodic tasks.
  460. *
  461. * @publicApi
  462. */
  463. function discardPeriodicTasksFallback() {
  464. var zoneSpec = _getFakeAsyncZoneSpec();
  465. zoneSpec.pendingPeriodicTimers.length = 0;
  466. }
  467. /**
  468. * Flush any pending microtasks.
  469. *
  470. * @publicApi
  471. */
  472. function flushMicrotasksFallback() {
  473. _getFakeAsyncZoneSpec().flushMicrotasks();
  474. }
  475. /**
  476. * @license
  477. * Copyright Google Inc. All Rights Reserved.
  478. *
  479. * Use of this source code is governed by an MIT-style license that can be
  480. * found in the LICENSE file at https://angular.io/license
  481. */
  482. var _Zone$1 = typeof Zone !== 'undefined' ? Zone : null;
  483. var fakeAsyncTestModule = _Zone$1 && _Zone$1[_Zone$1.__symbol__('fakeAsyncTest')];
  484. /**
  485. * Clears out the shared fake async zone for a test.
  486. * To be called in a global `beforeEach`.
  487. *
  488. * @publicApi
  489. */
  490. function resetFakeAsyncZone() {
  491. if (fakeAsyncTestModule) {
  492. return fakeAsyncTestModule.resetFakeAsyncZone();
  493. }
  494. else {
  495. return resetFakeAsyncZoneFallback();
  496. }
  497. }
  498. /**
  499. * Wraps a function to be executed in the fakeAsync zone:
  500. * - microtasks are manually executed by calling `flushMicrotasks()`,
  501. * - timers are synchronous, `tick()` simulates the asynchronous passage of time.
  502. *
  503. * If there are any pending timers at the end of the function, an exception will be thrown.
  504. *
  505. * Can be used to wrap inject() calls.
  506. *
  507. * @usageNotes
  508. * ### Example
  509. *
  510. * {@example core/testing/ts/fake_async.ts region='basic'}
  511. *
  512. * @param fn
  513. * @returns The function wrapped to be executed in the fakeAsync zone
  514. *
  515. * @publicApi
  516. */
  517. function fakeAsync(fn) {
  518. if (fakeAsyncTestModule) {
  519. return fakeAsyncTestModule.fakeAsync(fn);
  520. }
  521. else {
  522. return fakeAsyncFallback(fn);
  523. }
  524. }
  525. /**
  526. * Simulates the asynchronous passage of time for the timers in the fakeAsync zone.
  527. *
  528. * The microtasks queue is drained at the very start of this function and after any timer callback
  529. * has been executed.
  530. *
  531. * @usageNotes
  532. * ### Example
  533. *
  534. * {@example core/testing/ts/fake_async.ts region='basic'}
  535. *
  536. * @publicApi
  537. */
  538. function tick(millis) {
  539. if (millis === void 0) { millis = 0; }
  540. if (fakeAsyncTestModule) {
  541. return fakeAsyncTestModule.tick(millis);
  542. }
  543. else {
  544. return tickFallback(millis);
  545. }
  546. }
  547. /**
  548. * Simulates the asynchronous passage of time for the timers in the fakeAsync zone by
  549. * draining the macrotask queue until it is empty. The returned value is the milliseconds
  550. * of time that would have been elapsed.
  551. *
  552. * @param maxTurns
  553. * @returns The simulated time elapsed, in millis.
  554. *
  555. * @publicApi
  556. */
  557. function flush(maxTurns) {
  558. if (fakeAsyncTestModule) {
  559. return fakeAsyncTestModule.flush(maxTurns);
  560. }
  561. else {
  562. return flushFallback(maxTurns);
  563. }
  564. }
  565. /**
  566. * Discard all remaining periodic tasks.
  567. *
  568. * @publicApi
  569. */
  570. function discardPeriodicTasks() {
  571. if (fakeAsyncTestModule) {
  572. return fakeAsyncTestModule.discardPeriodicTasks();
  573. }
  574. else {
  575. discardPeriodicTasksFallback();
  576. }
  577. }
  578. /**
  579. * Flush any pending microtasks.
  580. *
  581. * @publicApi
  582. */
  583. function flushMicrotasks() {
  584. if (fakeAsyncTestModule) {
  585. return fakeAsyncTestModule.flushMicrotasks();
  586. }
  587. else {
  588. return flushMicrotasksFallback();
  589. }
  590. }
  591. /**
  592. * @license
  593. * Copyright Google Inc. All Rights Reserved.
  594. *
  595. * Use of this source code is governed by an MIT-style license that can be
  596. * found in the LICENSE file at https://angular.io/license
  597. */
  598. /**
  599. * Injectable completer that allows signaling completion of an asynchronous test. Used internally.
  600. */
  601. var AsyncTestCompleter = /** @class */ (function () {
  602. function AsyncTestCompleter() {
  603. var _this = this;
  604. this._promise = new Promise(function (res, rej) {
  605. _this._resolve = res;
  606. _this._reject = rej;
  607. });
  608. }
  609. AsyncTestCompleter.prototype.done = function (value) { this._resolve(value); };
  610. AsyncTestCompleter.prototype.fail = function (error, stackTrace) { this._reject(error); };
  611. Object.defineProperty(AsyncTestCompleter.prototype, "promise", {
  612. get: function () { return this._promise; },
  613. enumerable: true,
  614. configurable: true
  615. });
  616. return AsyncTestCompleter;
  617. }());
  618. /**
  619. * @license
  620. * Copyright Google Inc. All Rights Reserved.
  621. *
  622. * Use of this source code is governed by an MIT-style license that can be
  623. * found in the LICENSE file at https://angular.io/license
  624. */
  625. /**
  626. * An abstract class for inserting the root test component element in a platform independent way.
  627. *
  628. * @publicApi
  629. */
  630. var TestComponentRenderer = /** @class */ (function () {
  631. function TestComponentRenderer() {
  632. }
  633. TestComponentRenderer.prototype.insertRootElement = function (rootElementId) { };
  634. return TestComponentRenderer;
  635. }());
  636. /**
  637. * @publicApi
  638. */
  639. var ComponentFixtureAutoDetect = new InjectionToken('ComponentFixtureAutoDetect');
  640. /**
  641. * @publicApi
  642. */
  643. var ComponentFixtureNoNgZone = new InjectionToken('ComponentFixtureNoNgZone');
  644. /**
  645. * @license
  646. * Copyright Google Inc. All Rights Reserved.
  647. *
  648. * Use of this source code is governed by an MIT-style license that can be
  649. * found in the LICENSE file at https://angular.io/license
  650. */
  651. /**
  652. * Used to resolve resource URLs on `@Component` when used with JIT compilation.
  653. *
  654. * Example:
  655. * ```
  656. * @Component({
  657. * selector: 'my-comp',
  658. * templateUrl: 'my-comp.html', // This requires asynchronous resolution
  659. * })
  660. * class MyComponent{
  661. * }
  662. *
  663. * // Calling `renderComponent` will fail because `renderComponent` is a synchronous process
  664. * // and `MyComponent`'s `@Component.templateUrl` needs to be resolved asynchronously.
  665. *
  666. * // Calling `resolveComponentResources()` will resolve `@Component.templateUrl` into
  667. * // `@Component.template`, which allows `renderComponent` to proceed in a synchronous manner.
  668. *
  669. * // Use browser's `fetch()` function as the default resource resolution strategy.
  670. * resolveComponentResources(fetch).then(() => {
  671. * // After resolution all URLs have been converted into `template` strings.
  672. * renderComponent(MyComponent);
  673. * });
  674. *
  675. * ```
  676. *
  677. * NOTE: In AOT the resolution happens during compilation, and so there should be no need
  678. * to call this method outside JIT mode.
  679. *
  680. * @param resourceResolver a function which is responsible for returning a `Promise` to the
  681. * contents of the resolved URL. Browser's `fetch()` method is a good default implementation.
  682. */
  683. function resolveComponentResources(resourceResolver) {
  684. // Store all promises which are fetching the resources.
  685. var componentResolved = [];
  686. // Cache so that we don't fetch the same resource more than once.
  687. var urlMap = new Map();
  688. function cachedResourceResolve(url) {
  689. var promise = urlMap.get(url);
  690. if (!promise) {
  691. var resp = resourceResolver(url);
  692. urlMap.set(url, promise = resp.then(unwrapResponse));
  693. }
  694. return promise;
  695. }
  696. componentResourceResolutionQueue.forEach(function (component, type) {
  697. var promises = [];
  698. if (component.templateUrl) {
  699. promises.push(cachedResourceResolve(component.templateUrl).then(function (template) {
  700. component.template = template;
  701. }));
  702. }
  703. var styleUrls = component.styleUrls;
  704. var styles = component.styles || (component.styles = []);
  705. var styleOffset = component.styles.length;
  706. styleUrls && styleUrls.forEach(function (styleUrl, index) {
  707. styles.push(''); // pre-allocate array.
  708. promises.push(cachedResourceResolve(styleUrl).then(function (style) {
  709. styles[styleOffset + index] = style;
  710. styleUrls.splice(styleUrls.indexOf(styleUrl), 1);
  711. if (styleUrls.length == 0) {
  712. component.styleUrls = undefined;
  713. }
  714. }));
  715. });
  716. var fullyResolved = Promise.all(promises).then(function () { return componentDefResolved(type); });
  717. componentResolved.push(fullyResolved);
  718. });
  719. clearResolutionOfComponentResourcesQueue();
  720. return Promise.all(componentResolved).then(function () { return undefined; });
  721. }
  722. var componentResourceResolutionQueue = new Map();
  723. // Track when existing ngComponentDef for a Type is waiting on resources.
  724. var componentDefPendingResolution = new Set();
  725. function isComponentDefPendingResolution(type) {
  726. return componentDefPendingResolution.has(type);
  727. }
  728. function clearResolutionOfComponentResourcesQueue() {
  729. var old = componentResourceResolutionQueue;
  730. componentResourceResolutionQueue = new Map();
  731. return old;
  732. }
  733. function restoreComponentResolutionQueue(queue) {
  734. componentDefPendingResolution.clear();
  735. queue.forEach(function (_, type) { return componentDefPendingResolution.add(type); });
  736. componentResourceResolutionQueue = queue;
  737. }
  738. function unwrapResponse(response) {
  739. return typeof response == 'string' ? response : response.text();
  740. }
  741. function componentDefResolved(type) {
  742. componentDefPendingResolution.delete(type);
  743. }
  744. /**
  745. * @license
  746. * Copyright Google Inc. All Rights Reserved.
  747. *
  748. * Use of this source code is governed by an MIT-style license that can be
  749. * found in the LICENSE file at https://angular.io/license
  750. */
  751. var _nextReferenceId = 0;
  752. var MetadataOverrider = /** @class */ (function () {
  753. function MetadataOverrider() {
  754. this._references = new Map();
  755. }
  756. /**
  757. * Creates a new instance for the given metadata class
  758. * based on an old instance and overrides.
  759. */
  760. MetadataOverrider.prototype.overrideMetadata = function (metadataClass, oldMetadata, override) {
  761. var props = {};
  762. if (oldMetadata) {
  763. _valueProps(oldMetadata).forEach(function (prop) { return props[prop] = oldMetadata[prop]; });
  764. }
  765. if (override.set) {
  766. if (override.remove || override.add) {
  767. throw new Error("Cannot set and add/remove " + ɵstringify(metadataClass) + " at the same time!");
  768. }
  769. setMetadata(props, override.set);
  770. }
  771. if (override.remove) {
  772. removeMetadata(props, override.remove, this._references);
  773. }
  774. if (override.add) {
  775. addMetadata(props, override.add);
  776. }
  777. return new metadataClass(props);
  778. };
  779. return MetadataOverrider;
  780. }());
  781. function removeMetadata(metadata, remove, references) {
  782. var removeObjects = new Set();
  783. var _loop_1 = function (prop) {
  784. var removeValue = remove[prop];
  785. if (removeValue instanceof Array) {
  786. removeValue.forEach(function (value) { removeObjects.add(_propHashKey(prop, value, references)); });
  787. }
  788. else {
  789. removeObjects.add(_propHashKey(prop, removeValue, references));
  790. }
  791. };
  792. for (var prop in remove) {
  793. _loop_1(prop);
  794. }
  795. var _loop_2 = function (prop) {
  796. var propValue = metadata[prop];
  797. if (propValue instanceof Array) {
  798. metadata[prop] = propValue.filter(function (value) { return !removeObjects.has(_propHashKey(prop, value, references)); });
  799. }
  800. else {
  801. if (removeObjects.has(_propHashKey(prop, propValue, references))) {
  802. metadata[prop] = undefined;
  803. }
  804. }
  805. };
  806. for (var prop in metadata) {
  807. _loop_2(prop);
  808. }
  809. }
  810. function addMetadata(metadata, add) {
  811. for (var prop in add) {
  812. var addValue = add[prop];
  813. var propValue = metadata[prop];
  814. if (propValue != null && propValue instanceof Array) {
  815. metadata[prop] = propValue.concat(addValue);
  816. }
  817. else {
  818. metadata[prop] = addValue;
  819. }
  820. }
  821. }
  822. function setMetadata(metadata, set) {
  823. for (var prop in set) {
  824. metadata[prop] = set[prop];
  825. }
  826. }
  827. function _propHashKey(propName, propValue, references) {
  828. var replacer = function (key, value) {
  829. if (typeof value === 'function') {
  830. value = _serializeReference(value, references);
  831. }
  832. return value;
  833. };
  834. return propName + ":" + JSON.stringify(propValue, replacer);
  835. }
  836. function _serializeReference(ref, references) {
  837. var id = references.get(ref);
  838. if (!id) {
  839. id = "" + ɵstringify(ref) + _nextReferenceId++;
  840. references.set(ref, id);
  841. }
  842. return id;
  843. }
  844. function _valueProps(obj) {
  845. var props = [];
  846. // regular public props
  847. Object.keys(obj).forEach(function (prop) {
  848. if (!prop.startsWith('_')) {
  849. props.push(prop);
  850. }
  851. });
  852. // getters
  853. var proto = obj;
  854. while (proto = Object.getPrototypeOf(proto)) {
  855. Object.keys(proto).forEach(function (protoProp) {
  856. var desc = Object.getOwnPropertyDescriptor(proto, protoProp);
  857. if (!protoProp.startsWith('_') && desc && 'get' in desc) {
  858. props.push(protoProp);
  859. }
  860. });
  861. }
  862. return props;
  863. }
  864. /**
  865. * @license
  866. * Copyright Google Inc. All Rights Reserved.
  867. *
  868. * Use of this source code is governed by an MIT-style license that can be
  869. * found in the LICENSE file at https://angular.io/license
  870. */
  871. var reflection = new ɵReflectionCapabilities();
  872. /**
  873. * Allows to override ivy metadata for tests (via the `TestBed`).
  874. */
  875. var OverrideResolver = /** @class */ (function () {
  876. function OverrideResolver() {
  877. this.overrides = new Map();
  878. this.resolved = new Map();
  879. }
  880. OverrideResolver.prototype.addOverride = function (type, override) {
  881. var overrides = this.overrides.get(type) || [];
  882. overrides.push(override);
  883. this.overrides.set(type, overrides);
  884. this.resolved.delete(type);
  885. };
  886. OverrideResolver.prototype.setOverrides = function (overrides) {
  887. var _this = this;
  888. this.overrides.clear();
  889. overrides.forEach(function (_a) {
  890. var _b = __read(_a, 2), type = _b[0], override = _b[1];
  891. _this.addOverride(type, override);
  892. });
  893. };
  894. OverrideResolver.prototype.getAnnotation = function (type) {
  895. var annotations = reflection.annotations(type);
  896. // Try to find the nearest known Type annotation and make sure that this annotation is an
  897. // instance of the type we are looking for, so we can use it for resolution. Note: there might
  898. // be multiple known annotations found due to the fact that Components can extend Directives (so
  899. // both Directive and Component annotations would be present), so we always check if the known
  900. // annotation has the right type.
  901. for (var i = annotations.length - 1; i >= 0; i--) {
  902. var annotation = annotations[i];
  903. var isKnownType = annotation instanceof Directive || annotation instanceof Component ||
  904. annotation instanceof Pipe || annotation instanceof NgModule;
  905. if (isKnownType) {
  906. return annotation instanceof this.type ? annotation : null;
  907. }
  908. }
  909. return null;
  910. };
  911. OverrideResolver.prototype.resolve = function (type) {
  912. var _this = this;
  913. var resolved = this.resolved.get(type) || null;
  914. if (!resolved) {
  915. resolved = this.getAnnotation(type);
  916. if (resolved) {
  917. var overrides = this.overrides.get(type);
  918. if (overrides) {
  919. var overrider_1 = new MetadataOverrider();
  920. overrides.forEach(function (override) {
  921. resolved = overrider_1.overrideMetadata(_this.type, resolved, override);
  922. });
  923. }
  924. }
  925. this.resolved.set(type, resolved);
  926. }
  927. return resolved;
  928. };
  929. return OverrideResolver;
  930. }());
  931. var DirectiveResolver = /** @class */ (function (_super) {
  932. __extends(DirectiveResolver, _super);
  933. function DirectiveResolver() {
  934. return _super !== null && _super.apply(this, arguments) || this;
  935. }
  936. Object.defineProperty(DirectiveResolver.prototype, "type", {
  937. get: function () { return Directive; },
  938. enumerable: true,
  939. configurable: true
  940. });
  941. return DirectiveResolver;
  942. }(OverrideResolver));
  943. var ComponentResolver = /** @class */ (function (_super) {
  944. __extends(ComponentResolver, _super);
  945. function ComponentResolver() {
  946. return _super !== null && _super.apply(this, arguments) || this;
  947. }
  948. Object.defineProperty(ComponentResolver.prototype, "type", {
  949. get: function () { return Component; },
  950. enumerable: true,
  951. configurable: true
  952. });
  953. return ComponentResolver;
  954. }(OverrideResolver));
  955. var PipeResolver = /** @class */ (function (_super) {
  956. __extends(PipeResolver, _super);
  957. function PipeResolver() {
  958. return _super !== null && _super.apply(this, arguments) || this;
  959. }
  960. Object.defineProperty(PipeResolver.prototype, "type", {
  961. get: function () { return Pipe; },
  962. enumerable: true,
  963. configurable: true
  964. });
  965. return PipeResolver;
  966. }(OverrideResolver));
  967. var NgModuleResolver = /** @class */ (function (_super) {
  968. __extends(NgModuleResolver, _super);
  969. function NgModuleResolver() {
  970. return _super !== null && _super.apply(this, arguments) || this;
  971. }
  972. Object.defineProperty(NgModuleResolver.prototype, "type", {
  973. get: function () { return NgModule; },
  974. enumerable: true,
  975. configurable: true
  976. });
  977. return NgModuleResolver;
  978. }(OverrideResolver));
  979. /**
  980. * @license
  981. * Copyright Google Inc. All Rights Reserved.
  982. *
  983. * Use of this source code is governed by an MIT-style license that can be
  984. * found in the LICENSE file at https://angular.io/license
  985. */
  986. var TestingModuleOverride;
  987. (function (TestingModuleOverride) {
  988. TestingModuleOverride[TestingModuleOverride["DECLARATION"] = 0] = "DECLARATION";
  989. TestingModuleOverride[TestingModuleOverride["OVERRIDE_TEMPLATE"] = 1] = "OVERRIDE_TEMPLATE";
  990. })(TestingModuleOverride || (TestingModuleOverride = {}));
  991. function isTestingModuleOverride(value) {
  992. return value === TestingModuleOverride.DECLARATION ||
  993. value === TestingModuleOverride.OVERRIDE_TEMPLATE;
  994. }
  995. var R3TestBedCompiler = /** @class */ (function () {
  996. function R3TestBedCompiler(platform, additionalModuleTypes) {
  997. this.platform = platform;
  998. this.additionalModuleTypes = additionalModuleTypes;
  999. this.originalComponentResolutionQueue = null;
  1000. // Testing module configuration
  1001. this.declarations = [];
  1002. this.imports = [];
  1003. this.providers = [];
  1004. this.schemas = [];
  1005. // Queues of components/directives/pipes that should be recompiled.
  1006. this.pendingComponents = new Set();
  1007. this.pendingDirectives = new Set();
  1008. this.pendingPipes = new Set();
  1009. // Keep track of all components and directives, so we can patch Providers onto defs later.
  1010. this.seenComponents = new Set();
  1011. this.seenDirectives = new Set();
  1012. // Store resolved styles for Components that have template overrides present and `styleUrls`
  1013. // defined at the same time.
  1014. this.existingComponentStyles = new Map();
  1015. this.resolvers = initResolvers();
  1016. this.componentToModuleScope = new Map();
  1017. // Map that keeps initial version of component/directive/pipe defs in case
  1018. // we compile a Type again, thus overriding respective static fields. This is
  1019. // required to make sure we restore defs to their initial states between test runs
  1020. // TODO: we should support the case with multiple defs on a type
  1021. this.initialNgDefs = new Map();
  1022. // Array that keeps cleanup operations for initial versions of component/directive/pipe/module
  1023. // defs in case TestBed makes changes to the originals.
  1024. this.defCleanupOps = [];
  1025. this._injector = null;
  1026. this.compilerProviders = null;
  1027. this.providerOverrides = [];
  1028. this.rootProviderOverrides = [];
  1029. this.providerOverridesByToken = new Map();
  1030. this.moduleProvidersOverridden = new Set();
  1031. this.testModuleRef = null;
  1032. var DynamicTestModule = /** @class */ (function () {
  1033. function DynamicTestModule() {
  1034. }
  1035. return DynamicTestModule;
  1036. }());
  1037. this.testModuleType = DynamicTestModule;
  1038. }
  1039. R3TestBedCompiler.prototype.setCompilerProviders = function (providers) {
  1040. this.compilerProviders = providers;
  1041. this._injector = null;
  1042. };
  1043. R3TestBedCompiler.prototype.configureTestingModule = function (moduleDef) {
  1044. var _a, _b, _c, _d;
  1045. // Enqueue any compilation tasks for the directly declared component.
  1046. if (moduleDef.declarations !== undefined) {
  1047. this.queueTypeArray(moduleDef.declarations, TestingModuleOverride.DECLARATION);
  1048. (_a = this.declarations).push.apply(_a, __spread(moduleDef.declarations));
  1049. }
  1050. // Enqueue any compilation tasks for imported modules.
  1051. if (moduleDef.imports !== undefined) {
  1052. this.queueTypesFromModulesArray(moduleDef.imports);
  1053. (_b = this.imports).push.apply(_b, __spread(moduleDef.imports));
  1054. }
  1055. if (moduleDef.providers !== undefined) {
  1056. (_c = this.providers).push.apply(_c, __spread(moduleDef.providers));
  1057. }
  1058. if (moduleDef.schemas !== undefined) {
  1059. (_d = this.schemas).push.apply(_d, __spread(moduleDef.schemas));
  1060. }
  1061. };
  1062. R3TestBedCompiler.prototype.overrideModule = function (ngModule, override) {
  1063. // Compile the module right away.
  1064. this.resolvers.module.addOverride(ngModule, override);
  1065. var metadata = this.resolvers.module.resolve(ngModule);
  1066. if (metadata === null) {
  1067. throw new Error(ngModule.name + " is not an @NgModule or is missing metadata");
  1068. }
  1069. this.recompileNgModule(ngModule);
  1070. // At this point, the module has a valid .ngModuleDef, but the override may have introduced
  1071. // new declarations or imported modules. Ingest any possible new types and add them to the
  1072. // current queue.
  1073. this.queueTypesFromModulesArray([ngModule]);
  1074. };
  1075. R3TestBedCompiler.prototype.overrideComponent = function (component, override) {
  1076. this.resolvers.component.addOverride(component, override);
  1077. this.pendingComponents.add(component);
  1078. };
  1079. R3TestBedCompiler.prototype.overrideDirective = function (directive, override) {
  1080. this.resolvers.directive.addOverride(directive, override);
  1081. this.pendingDirectives.add(directive);
  1082. };
  1083. R3TestBedCompiler.prototype.overridePipe = function (pipe, override) {
  1084. this.resolvers.pipe.addOverride(pipe, override);
  1085. this.pendingPipes.add(pipe);
  1086. };
  1087. R3TestBedCompiler.prototype.overrideProvider = function (token, provider) {
  1088. var providerDef = provider.useFactory ?
  1089. {
  1090. provide: token,
  1091. useFactory: provider.useFactory,
  1092. deps: provider.deps || [],
  1093. multi: provider.multi,
  1094. } :
  1095. { provide: token, useValue: provider.useValue, multi: provider.multi };
  1096. var injectableDef;
  1097. var isRoot = (typeof token !== 'string' && (injectableDef = ɵgetInjectableDef(token)) &&
  1098. injectableDef.providedIn === 'root');
  1099. var overridesBucket = isRoot ? this.rootProviderOverrides : this.providerOverrides;
  1100. overridesBucket.push(providerDef);
  1101. // Keep overrides grouped by token as well for fast lookups using token
  1102. this.providerOverridesByToken.set(token, providerDef);
  1103. };
  1104. R3TestBedCompiler.prototype.overrideTemplateUsingTestingModule = function (type, template) {
  1105. var _this = this;
  1106. var def = type[ɵNG_COMPONENT_DEF];
  1107. var hasStyleUrls = function () {
  1108. var metadata = _this.resolvers.component.resolve(type);
  1109. return !!metadata.styleUrls && metadata.styleUrls.length > 0;
  1110. };
  1111. var overrideStyleUrls = !!def && !isComponentDefPendingResolution(type) && hasStyleUrls();
  1112. // In Ivy, compiling a component does not require knowing the module providing the
  1113. // component's scope, so overrideTemplateUsingTestingModule can be implemented purely via
  1114. // overrideComponent. Important: overriding template requires full Component re-compilation,
  1115. // which may fail in case styleUrls are also present (thus Component is considered as required
  1116. // resolution). In order to avoid this, we preemptively set styleUrls to an empty array,
  1117. // preserve current styles available on Component def and restore styles back once compilation
  1118. // is complete.
  1119. var override = overrideStyleUrls ? { template: template, styles: [], styleUrls: [] } : { template: template };
  1120. this.overrideComponent(type, { set: override });
  1121. if (overrideStyleUrls && def.styles && def.styles.length > 0) {
  1122. this.existingComponentStyles.set(type, def.styles);
  1123. }
  1124. // Set the component's scope to be the testing module.
  1125. this.componentToModuleScope.set(type, TestingModuleOverride.OVERRIDE_TEMPLATE);
  1126. };
  1127. R3TestBedCompiler.prototype.compileComponents = function () {
  1128. return __awaiter(this, void 0, void 0, function () {
  1129. var needsAsyncResources, resourceLoader_1, resolver;
  1130. var _this = this;
  1131. return __generator(this, function (_a) {
  1132. switch (_a.label) {
  1133. case 0:
  1134. this.clearComponentResolutionQueue();
  1135. needsAsyncResources = this.compileTypesSync();
  1136. if (!needsAsyncResources) return [3 /*break*/, 2];
  1137. resolver = function (url) {
  1138. if (!resourceLoader_1) {
  1139. resourceLoader_1 = _this.injector.get(ResourceLoader);
  1140. }
  1141. return Promise.resolve(resourceLoader_1.get(url));
  1142. };
  1143. return [4 /*yield*/, resolveComponentResources(resolver)];
  1144. case 1:
  1145. _a.sent();
  1146. _a.label = 2;
  1147. case 2: return [2 /*return*/];
  1148. }
  1149. });
  1150. });
  1151. };
  1152. R3TestBedCompiler.prototype.finalize = function () {
  1153. // One last compile
  1154. this.compileTypesSync();
  1155. // Create the testing module itself.
  1156. this.compileTestModule();
  1157. this.applyTransitiveScopes();
  1158. this.applyProviderOverrides();
  1159. // Patch previously stored `styles` Component values (taken from ngComponentDef), in case these
  1160. // Components have `styleUrls` fields defined and template override was requested.
  1161. this.patchComponentsWithExistingStyles();
  1162. // Clear the componentToModuleScope map, so that future compilations don't reset the scope of
  1163. // every component.
  1164. this.componentToModuleScope.clear();
  1165. var parentInjector = this.platform.injector;
  1166. this.testModuleRef = new ɵRender3NgModuleRef(this.testModuleType, parentInjector);
  1167. // Set the locale ID, it can be overridden for the tests
  1168. var localeId = this.testModuleRef.injector.get(LOCALE_ID, ɵDEFAULT_LOCALE_ID);
  1169. ɵsetLocaleId(localeId);
  1170. // ApplicationInitStatus.runInitializers() is marked @internal to core.
  1171. // Cast it to any before accessing it.
  1172. this.testModuleRef.injector.get(ApplicationInitStatus).runInitializers();
  1173. return this.testModuleRef;
  1174. };
  1175. /**
  1176. * @internal
  1177. */
  1178. R3TestBedCompiler.prototype._compileNgModuleSync = function (moduleType) {
  1179. this.queueTypesFromModulesArray([moduleType]);
  1180. this.compileTypesSync();
  1181. this.applyProviderOverrides();
  1182. this.applyProviderOverridesToModule(moduleType);
  1183. this.applyTransitiveScopes();
  1184. };
  1185. /**
  1186. * @internal
  1187. */
  1188. R3TestBedCompiler.prototype._compileNgModuleAsync = function (moduleType) {
  1189. return __awaiter(this, void 0, void 0, function () {
  1190. return __generator(this, function (_a) {
  1191. switch (_a.label) {
  1192. case 0:
  1193. this.queueTypesFromModulesArray([moduleType]);
  1194. return [4 /*yield*/, this.compileComponents()];
  1195. case 1:
  1196. _a.sent();
  1197. this.applyProviderOverrides();
  1198. this.applyProviderOverridesToModule(moduleType);
  1199. this.applyTransitiveScopes();
  1200. return [2 /*return*/];
  1201. }
  1202. });
  1203. });
  1204. };
  1205. /**
  1206. * @internal
  1207. */
  1208. R3TestBedCompiler.prototype._getModuleResolver = function () { return this.resolvers.module; };
  1209. /**
  1210. * @internal
  1211. */
  1212. R3TestBedCompiler.prototype._getComponentFactories = function (moduleType) {
  1213. var _this = this;
  1214. return maybeUnwrapFn(moduleType.ngModuleDef.declarations).reduce(function (factories, declaration) {
  1215. var componentDef = declaration.ngComponentDef;
  1216. componentDef && factories.push(new ɵRender3ComponentFactory(componentDef, _this.testModuleRef));
  1217. return factories;
  1218. }, []);
  1219. };
  1220. R3TestBedCompiler.prototype.compileTypesSync = function () {
  1221. var _this = this;
  1222. // Compile all queued components, directives, pipes.
  1223. var needsAsyncResources = false;
  1224. this.pendingComponents.forEach(function (declaration) {
  1225. needsAsyncResources = needsAsyncResources || isComponentDefPendingResolution(declaration);
  1226. var metadata = _this.resolvers.component.resolve(declaration);
  1227. _this.maybeStoreNgDef(ɵNG_COMPONENT_DEF, declaration);
  1228. ɵcompileComponent(declaration, metadata);
  1229. });
  1230. this.pendingComponents.clear();
  1231. this.pendingDirectives.forEach(function (declaration) {
  1232. var metadata = _this.resolvers.directive.resolve(declaration);
  1233. _this.maybeStoreNgDef(ɵNG_DIRECTIVE_DEF, declaration);
  1234. ɵcompileDirective(declaration, metadata);
  1235. });
  1236. this.pendingDirectives.clear();
  1237. this.pendingPipes.forEach(function (declaration) {
  1238. var metadata = _this.resolvers.pipe.resolve(declaration);
  1239. _this.maybeStoreNgDef(ɵNG_PIPE_DEF, declaration);
  1240. ɵcompilePipe(declaration, metadata);
  1241. });
  1242. this.pendingPipes.clear();
  1243. return needsAsyncResources;
  1244. };
  1245. R3TestBedCompiler.prototype.applyTransitiveScopes = function () {
  1246. var _this = this;
  1247. var moduleToScope = new Map();
  1248. var getScopeOfModule = function (moduleType) {
  1249. if (!moduleToScope.has(moduleType)) {
  1250. var realType = isTestingModuleOverride(moduleType) ? _this.testModuleType : moduleType;
  1251. moduleToScope.set(moduleType, ɵtransitiveScopesFor(realType));
  1252. }
  1253. return moduleToScope.get(moduleType);
  1254. };
  1255. this.componentToModuleScope.forEach(function (moduleType, componentType) {
  1256. var moduleScope = getScopeOfModule(moduleType);
  1257. _this.storeFieldOfDefOnType(componentType, ɵNG_COMPONENT_DEF, 'directiveDefs');
  1258. _this.storeFieldOfDefOnType(componentType, ɵNG_COMPONENT_DEF, 'pipeDefs');
  1259. ɵpatchComponentDefWithScope(componentType.ngComponentDef, moduleScope);
  1260. });
  1261. this.componentToModuleScope.clear();
  1262. };
  1263. R3TestBedCompiler.prototype.applyProviderOverrides = function () {
  1264. var _this = this;
  1265. var maybeApplyOverrides = function (field) { return function (type) {
  1266. var resolver = field === ɵNG_COMPONENT_DEF ? _this.resolvers.component : _this.resolvers.directive;
  1267. var metadata = resolver.resolve(type);
  1268. if (_this.hasProviderOverrides(metadata.providers)) {
  1269. _this.patchDefWithProviderOverrides(type, field);
  1270. }
  1271. }; };
  1272. this.seenComponents.forEach(maybeApplyOverrides(ɵNG_COMPONENT_DEF));
  1273. this.seenDirectives.forEach(maybeApplyOverrides(ɵNG_DIRECTIVE_DEF));
  1274. this.seenComponents.clear();
  1275. this.seenDirectives.clear();
  1276. };
  1277. R3TestBedCompiler.prototype.applyProviderOverridesToModule = function (moduleType) {
  1278. var e_1, _a;
  1279. if (this.moduleProvidersOverridden.has(moduleType)) {
  1280. return;
  1281. }
  1282. this.moduleProvidersOverridden.add(moduleType);
  1283. var injectorDef = moduleType[ɵNG_INJECTOR_DEF];
  1284. if (this.providerOverridesByToken.size > 0) {
  1285. if (this.hasProviderOverrides(injectorDef.providers)) {
  1286. this.maybeStoreNgDef(ɵNG_INJECTOR_DEF, moduleType);
  1287. this.storeFieldOfDefOnType(moduleType, ɵNG_INJECTOR_DEF, 'providers');
  1288. injectorDef.providers = this.getOverriddenProviders(injectorDef.providers);
  1289. }
  1290. // Apply provider overrides to imported modules recursively
  1291. var moduleDef = moduleType[ɵNG_MODULE_DEF];
  1292. try {
  1293. for (var _b = __values(moduleDef.imports), _c = _b.next(); !_c.done; _c = _b.next()) {
  1294. var importType = _c.value;
  1295. this.applyProviderOverridesToModule(importType);
  1296. }
  1297. }
  1298. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  1299. finally {
  1300. try {
  1301. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  1302. }
  1303. finally { if (e_1) throw e_1.error; }
  1304. }
  1305. }
  1306. };
  1307. R3TestBedCompiler.prototype.patchComponentsWithExistingStyles = function () {
  1308. this.existingComponentStyles.forEach(function (styles, type) { return type[ɵNG_COMPONENT_DEF].styles = styles; });
  1309. this.existingComponentStyles.clear();
  1310. };
  1311. R3TestBedCompiler.prototype.queueTypeArray = function (arr, moduleType) {
  1312. var e_2, _a;
  1313. try {
  1314. for (var arr_1 = __values(arr), arr_1_1 = arr_1.next(); !arr_1_1.done; arr_1_1 = arr_1.next()) {
  1315. var value = arr_1_1.value;
  1316. if (Array.isArray(value)) {
  1317. this.queueTypeArray(value, moduleType);
  1318. }
  1319. else {
  1320. this.queueType(value, moduleType);
  1321. }
  1322. }
  1323. }
  1324. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  1325. finally {
  1326. try {
  1327. if (arr_1_1 && !arr_1_1.done && (_a = arr_1.return)) _a.call(arr_1);
  1328. }
  1329. finally { if (e_2) throw e_2.error; }
  1330. }
  1331. };
  1332. R3TestBedCompiler.prototype.recompileNgModule = function (ngModule) {
  1333. var metadata = this.resolvers.module.resolve(ngModule);
  1334. if (metadata === null) {
  1335. throw new Error("Unable to resolve metadata for NgModule: " + ngModule.name);
  1336. }
  1337. // Cache the initial ngModuleDef as it will be overwritten.
  1338. this.maybeStoreNgDef(ɵNG_MODULE_DEF, ngModule);
  1339. this.maybeStoreNgDef(ɵNG_INJECTOR_DEF, ngModule);
  1340. ɵcompileNgModuleDefs(ngModule, metadata);
  1341. };
  1342. R3TestBedCompiler.prototype.queueType = function (type, moduleType) {
  1343. var component = this.resolvers.component.resolve(type);
  1344. if (component) {
  1345. // Check whether a give Type has respective NG def (ngComponentDef) and compile if def is
  1346. // missing. That might happen in case a class without any Angular decorators extends another
  1347. // class where Component/Directive/Pipe decorator is defined.
  1348. if (isComponentDefPendingResolution(type) || !type.hasOwnProperty(ɵNG_COMPONENT_DEF)) {
  1349. this.pendingComponents.add(type);
  1350. }
  1351. this.seenComponents.add(type);
  1352. // Keep track of the module which declares this component, so later the component's scope
  1353. // can be set correctly. If the component has already been recorded here, then one of several
  1354. // cases is true:
  1355. // * the module containing the component was imported multiple times (common).
  1356. // * the component is declared in multiple modules (which is an error).
  1357. // * the component was in 'declarations' of the testing module, and also in an imported module
  1358. // in which case the module scope will be TestingModuleOverride.DECLARATION.
  1359. // * overrideTemplateUsingTestingModule was called for the component in which case the module
  1360. // scope will be TestingModuleOverride.OVERRIDE_TEMPLATE.
  1361. //
  1362. // If the component was previously in the testing module's 'declarations' (meaning the
  1363. // current value is TestingModuleOverride.DECLARATION), then `moduleType` is the component's
  1364. // real module, which was imported. This pattern is understood to mean that the component
  1365. // should use its original scope, but that the testing module should also contain the
  1366. // component in its scope.
  1367. if (!this.componentToModuleScope.has(type) ||
  1368. this.componentToModuleScope.get(type) === TestingModuleOverride.DECLARATION) {
  1369. this.componentToModuleScope.set(type, moduleType);
  1370. }
  1371. return;
  1372. }
  1373. var directive = this.resolvers.directive.resolve(type);
  1374. if (directive) {
  1375. if (!type.hasOwnProperty(ɵNG_DIRECTIVE_DEF)) {
  1376. this.pendingDirectives.add(type);
  1377. }
  1378. this.seenDirectives.add(type);
  1379. return;
  1380. }
  1381. var pipe = this.resolvers.pipe.resolve(type);
  1382. if (pipe && !type.hasOwnProperty(ɵNG_PIPE_DEF)) {
  1383. this.pendingPipes.add(type);
  1384. return;
  1385. }
  1386. };
  1387. R3TestBedCompiler.prototype.queueTypesFromModulesArray = function (arr) {
  1388. var e_3, _a;
  1389. try {
  1390. for (var arr_2 = __values(arr), arr_2_1 = arr_2.next(); !arr_2_1.done; arr_2_1 = arr_2.next()) {
  1391. var value = arr_2_1.value;
  1392. if (Array.isArray(value)) {
  1393. this.queueTypesFromModulesArray(value);
  1394. }
  1395. else if (hasNgModuleDef(value)) {
  1396. var def = value.ngModuleDef;
  1397. // Look through declarations, imports, and exports, and queue everything found there.
  1398. this.queueTypeArray(maybeUnwrapFn(def.declarations), value);
  1399. this.queueTypesFromModulesArray(maybeUnwrapFn(def.imports));
  1400. this.queueTypesFromModulesArray(maybeUnwrapFn(def.exports));
  1401. }
  1402. }
  1403. }
  1404. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  1405. finally {
  1406. try {
  1407. if (arr_2_1 && !arr_2_1.done && (_a = arr_2.return)) _a.call(arr_2);
  1408. }
  1409. finally { if (e_3) throw e_3.error; }
  1410. }
  1411. };
  1412. R3TestBedCompiler.prototype.maybeStoreNgDef = function (prop, type) {
  1413. if (!this.initialNgDefs.has(type)) {
  1414. var currentDef = Object.getOwnPropertyDescriptor(type, prop);
  1415. this.initialNgDefs.set(type, [prop, currentDef]);
  1416. }
  1417. };
  1418. R3TestBedCompiler.prototype.storeFieldOfDefOnType = function (type, defField, field) {
  1419. var def = type[defField];
  1420. var original = def[field];
  1421. this.defCleanupOps.push({ field: field, def: def, original: original });
  1422. };
  1423. /**
  1424. * Clears current components resolution queue, but stores the state of the queue, so we can
  1425. * restore it later. Clearing the queue is required before we try to compile components (via
  1426. * `TestBed.compileComponents`), so that component defs are in sync with the resolution queue.
  1427. */
  1428. R3TestBedCompiler.prototype.clearComponentResolutionQueue = function () {
  1429. var _this = this;
  1430. if (this.originalComponentResolutionQueue === null) {
  1431. this.originalComponentResolutionQueue = new Map();
  1432. }
  1433. clearResolutionOfComponentResourcesQueue().forEach(function (value, key) { return _this.originalComponentResolutionQueue.set(key, value); });
  1434. };
  1435. /*
  1436. * Restores component resolution queue to the previously saved state. This operation is performed
  1437. * as a part of restoring the state after completion of the current set of tests (that might
  1438. * potentially mutate the state).
  1439. */
  1440. R3TestBedCompiler.prototype.restoreComponentResolutionQueue = function () {
  1441. if (this.originalComponentResolutionQueue !== null) {
  1442. restoreComponentResolutionQueue(this.originalComponentResolutionQueue);
  1443. this.originalComponentResolutionQueue = null;
  1444. }
  1445. };
  1446. R3TestBedCompiler.prototype.restoreOriginalState = function () {
  1447. var e_4, _a;
  1448. try {
  1449. for (var _b = __values(this.defCleanupOps), _c = _b.next(); !_c.done; _c = _b.next()) {
  1450. var op = _c.value;
  1451. op.def[op.field] = op.original;
  1452. }
  1453. }
  1454. catch (e_4_1) { e_4 = { error: e_4_1 }; }
  1455. finally {
  1456. try {
  1457. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  1458. }
  1459. finally { if (e_4) throw e_4.error; }
  1460. }
  1461. // Restore initial component/directive/pipe defs
  1462. this.initialNgDefs.forEach(function (value, type) {
  1463. var _a = __read(value, 2), prop = _a[0], descriptor = _a[1];
  1464. if (!descriptor) {
  1465. // Delete operations are generally undesirable since they have performance implications
  1466. // on objects they were applied to. In this particular case, situations where this code is
  1467. // invoked should be quite rare to cause any noticable impact, since it's applied only to
  1468. // some test cases (for example when class with no annotations extends some @Component)
  1469. // when we need to clear 'ngComponentDef' field on a given class to restore its original
  1470. // state (before applying overrides and running tests).
  1471. delete type[prop];
  1472. }
  1473. else {
  1474. Object.defineProperty(type, prop, descriptor);
  1475. }
  1476. });
  1477. this.initialNgDefs.clear();
  1478. this.moduleProvidersOverridden.clear();
  1479. this.restoreComponentResolutionQueue();
  1480. // Restore the locale ID to the default value, this shouldn't be necessary but we never know
  1481. ɵsetLocaleId(ɵDEFAULT_LOCALE_ID);
  1482. };
  1483. R3TestBedCompiler.prototype.compileTestModule = function () {
  1484. var _this = this;
  1485. var RootScopeModule = /** @class */ (function () {
  1486. function RootScopeModule() {
  1487. }
  1488. return RootScopeModule;
  1489. }());
  1490. ɵcompileNgModuleDefs(RootScopeModule, {
  1491. providers: __spread(this.rootProviderOverrides),
  1492. });
  1493. var ngZone = new NgZone({ enableLongStackTrace: true });
  1494. var providers = __spread([
  1495. { provide: NgZone, useValue: ngZone },
  1496. { provide: Compiler, useFactory: function () { return new R3TestCompiler(_this); } }
  1497. ], this.providers, this.providerOverrides);
  1498. var imports = [RootScopeModule, this.additionalModuleTypes, this.imports || []];
  1499. // clang-format off
  1500. ɵcompileNgModuleDefs(this.testModuleType, {
  1501. declarations: this.declarations,
  1502. imports: imports,
  1503. schemas: this.schemas,
  1504. providers: providers,
  1505. }, /* allowDuplicateDeclarationsInRoot */ true);
  1506. // clang-format on
  1507. this.applyProviderOverridesToModule(this.testModuleType);
  1508. };
  1509. Object.defineProperty(R3TestBedCompiler.prototype, "injector", {
  1510. get: function () {
  1511. if (this._injector !== null) {
  1512. return this._injector;
  1513. }
  1514. var providers = [];
  1515. var compilerOptions = this.platform.injector.get(COMPILER_OPTIONS);
  1516. compilerOptions.forEach(function (opts) {
  1517. if (opts.providers) {
  1518. providers.push(opts.providers);
  1519. }
  1520. });
  1521. if (this.compilerProviders !== null) {
  1522. providers.push.apply(providers, __spread(this.compilerProviders));
  1523. }
  1524. // TODO(ocombe): make this work with an Injector directly instead of creating a module for it
  1525. var CompilerModule = /** @class */ (function () {
  1526. function CompilerModule() {
  1527. }
  1528. return CompilerModule;
  1529. }());
  1530. ɵcompileNgModuleDefs(CompilerModule, { providers: providers });
  1531. var CompilerModuleFactory = new ɵNgModuleFactory(CompilerModule);
  1532. this._injector = CompilerModuleFactory.create(this.platform.injector).injector;
  1533. return this._injector;
  1534. },
  1535. enumerable: true,
  1536. configurable: true
  1537. });
  1538. // get overrides for a specific provider (if any)
  1539. R3TestBedCompiler.prototype.getSingleProviderOverrides = function (provider) {
  1540. var token = getProviderToken(provider);
  1541. return this.providerOverridesByToken.get(token) || null;
  1542. };
  1543. R3TestBedCompiler.prototype.getProviderOverrides = function (providers) {
  1544. var _this = this;
  1545. if (!providers || !providers.length || this.providerOverridesByToken.size === 0)
  1546. return [];
  1547. // There are two flattening operations here. The inner flatten() operates on the metadata's
  1548. // providers and applies a mapping function which retrieves overrides for each incoming
  1549. // provider. The outer flatten() then flattens the produced overrides array. If this is not
  1550. // done, the array can contain other empty arrays (e.g. `[[], []]`) which leak into the
  1551. // providers array and contaminate any error messages that might be generated.
  1552. return flatten(flatten(providers, function (provider) { return _this.getSingleProviderOverrides(provider) || []; }));
  1553. };
  1554. R3TestBedCompiler.prototype.getOverriddenProviders = function (providers) {
  1555. var _this = this;
  1556. if (!providers || !providers.length || this.providerOverridesByToken.size === 0)
  1557. return [];
  1558. var overrides = this.getProviderOverrides(providers);
  1559. var hasMultiProviderOverrides = overrides.some(isMultiProvider);
  1560. var overriddenProviders = __spread(providers, overrides);
  1561. // No additional processing is required in case we have no multi providers to override
  1562. if (!hasMultiProviderOverrides) {
  1563. return overriddenProviders;
  1564. }
  1565. var final = [];
  1566. var seenMultiProviders = new Set();
  1567. // We iterate through the list of providers in reverse order to make sure multi provider
  1568. // overrides take precedence over the values defined in provider list. We also fiter out all
  1569. // multi providers that have overrides, keeping overridden values only.
  1570. forEachRight(overriddenProviders, function (provider) {
  1571. var token = getProviderToken(provider);
  1572. if (isMultiProvider(provider) && _this.providerOverridesByToken.has(token)) {
  1573. if (!seenMultiProviders.has(token)) {
  1574. seenMultiProviders.add(token);
  1575. if (provider && provider.useValue && Array.isArray(provider.useValue)) {
  1576. forEachRight(provider.useValue, function (value) {
  1577. // Unwrap provider override array into individual providers in final set.
  1578. final.unshift({ provide: token, useValue: value, multi: true });
  1579. });
  1580. }
  1581. else {
  1582. final.unshift(provider);
  1583. }
  1584. }
  1585. }
  1586. else {
  1587. final.unshift(provider);
  1588. }
  1589. });
  1590. return final;
  1591. };
  1592. R3TestBedCompiler.prototype.hasProviderOverrides = function (providers) {
  1593. return this.getProviderOverrides(providers).length > 0;
  1594. };
  1595. R3TestBedCompiler.prototype.patchDefWithProviderOverrides = function (declaration, field) {
  1596. var _this = this;
  1597. var def = declaration[field];
  1598. if (def && def.providersResolver) {
  1599. this.maybeStoreNgDef(field, declaration);
  1600. var resolver_1 = def.providersResolver;
  1601. var processProvidersFn_1 = function (providers) { return _this.getOverriddenProviders(providers); };
  1602. this.storeFieldOfDefOnType(declaration, field, 'providersResolver');
  1603. def.providersResolver = function (ngDef) { return resolver_1(ngDef, processProvidersFn_1); };
  1604. }
  1605. };
  1606. return R3TestBedCompiler;
  1607. }());
  1608. function initResolvers() {
  1609. return {
  1610. module: new NgModuleResolver(),
  1611. component: new ComponentResolver(),
  1612. directive: new DirectiveResolver(),
  1613. pipe: new PipeResolver()
  1614. };
  1615. }
  1616. function hasNgModuleDef(value) {
  1617. return value.hasOwnProperty('ngModuleDef');
  1618. }
  1619. function maybeUnwrapFn(maybeFn) {
  1620. return maybeFn instanceof Function ? maybeFn() : maybeFn;
  1621. }
  1622. function flatten(values, mapFn) {
  1623. var out = [];
  1624. values.forEach(function (value) {
  1625. if (Array.isArray(value)) {
  1626. out.push.apply(out, __spread(flatten(value, mapFn)));
  1627. }
  1628. else {
  1629. out.push(mapFn ? mapFn(value) : value);
  1630. }
  1631. });
  1632. return out;
  1633. }
  1634. function getProviderField(provider, field) {
  1635. return provider && typeof provider === 'object' && provider[field];
  1636. }
  1637. function getProviderToken(provider) {
  1638. return getProviderField(provider, 'provide') || provider;
  1639. }
  1640. function isMultiProvider(provider) {
  1641. return !!getProviderField(provider, 'multi');
  1642. }
  1643. function forEachRight(values, fn) {
  1644. for (var idx = values.length - 1; idx >= 0; idx--) {
  1645. fn(values[idx], idx);
  1646. }
  1647. }
  1648. var R3TestCompiler = /** @class */ (function () {
  1649. function R3TestCompiler(testBed) {
  1650. this.testBed = testBed;
  1651. }
  1652. R3TestCompiler.prototype.compileModuleSync = function (moduleType) {
  1653. this.testBed._compileNgModuleSync(moduleType);
  1654. return new ɵNgModuleFactory(moduleType);
  1655. };
  1656. R3TestCompiler.prototype.compileModuleAsync = function (moduleType) {
  1657. return __awaiter(this, void 0, void 0, function () {
  1658. return __generator(this, function (_a) {
  1659. switch (_a.label) {
  1660. case 0: return [4 /*yield*/, this.testBed._compileNgModuleAsync(moduleType)];
  1661. case 1:
  1662. _a.sent();
  1663. return [2 /*return*/, new ɵNgModuleFactory(moduleType)];
  1664. }
  1665. });
  1666. });
  1667. };
  1668. R3TestCompiler.prototype.compileModuleAndAllComponentsSync = function (moduleType) {
  1669. var ngModuleFactory = this.compileModuleSync(moduleType);
  1670. var componentFactories = this.testBed._getComponentFactories(moduleType);
  1671. return new ModuleWithComponentFactories(ngModuleFactory, componentFactories);
  1672. };
  1673. R3TestCompiler.prototype.compileModuleAndAllComponentsAsync = function (moduleType) {
  1674. return __awaiter(this, void 0, void 0, function () {
  1675. var ngModuleFactory, componentFactories;
  1676. return __generator(this, function (_a) {
  1677. switch (_a.label) {
  1678. case 0: return [4 /*yield*/, this.compileModuleAsync(moduleType)];
  1679. case 1:
  1680. ngModuleFactory = _a.sent();
  1681. componentFactories = this.testBed._getComponentFactories(moduleType);
  1682. return [2 /*return*/, new ModuleWithComponentFactories(ngModuleFactory, componentFactories)];
  1683. }
  1684. });
  1685. });
  1686. };
  1687. R3TestCompiler.prototype.clearCache = function () { };
  1688. R3TestCompiler.prototype.clearCacheFor = function (type) { };
  1689. R3TestCompiler.prototype.getModuleId = function (moduleType) {
  1690. var meta = this.testBed._getModuleResolver().resolve(moduleType);
  1691. return meta && meta.id || undefined;
  1692. };
  1693. return R3TestCompiler;
  1694. }());
  1695. /**
  1696. * @license
  1697. * Copyright Google Inc. All Rights Reserved.
  1698. *
  1699. * Use of this source code is governed by an MIT-style license that can be
  1700. * found in the LICENSE file at https://angular.io/license
  1701. */
  1702. var _nextRootElementId = 0;
  1703. var UNDEFINED = Symbol('UNDEFINED');
  1704. /**
  1705. * @description
  1706. * Configures and initializes environment for unit testing and provides methods for
  1707. * creating components and services in unit tests.
  1708. *
  1709. * TestBed is the primary api for writing unit tests for Angular applications and libraries.
  1710. *
  1711. * Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
  1712. * according to the compiler used.
  1713. */
  1714. var TestBedRender3 = /** @class */ (function () {
  1715. function TestBedRender3() {
  1716. // Properties
  1717. this.platform = null;
  1718. this.ngModule = null;
  1719. this._compiler = null;
  1720. this._testModuleRef = null;
  1721. this._activeFixtures = [];
  1722. this._globalCompilationChecked = false;
  1723. }
  1724. /**
  1725. * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
  1726. * angular module. These are common to every test in the suite.
  1727. *
  1728. * This may only be called once, to set up the common providers for the current test
  1729. * suite on the current platform. If you absolutely need to change the providers,
  1730. * first use `resetTestEnvironment`.
  1731. *
  1732. * Test modules and platforms for individual platforms are available from
  1733. * '@angular/<platform_name>/testing'.
  1734. *
  1735. * @publicApi
  1736. */
  1737. TestBedRender3.initTestEnvironment = function (ngModule, platform, aotSummaries) {
  1738. var testBed = _getTestBedRender3();
  1739. testBed.initTestEnvironment(ngModule, platform, aotSummaries);
  1740. return testBed;
  1741. };
  1742. /**
  1743. * Reset the providers for the test injector.
  1744. *
  1745. * @publicApi
  1746. */
  1747. TestBedRender3.resetTestEnvironment = function () { _getTestBedRender3().resetTestEnvironment(); };
  1748. TestBedRender3.configureCompiler = function (config) {
  1749. _getTestBedRender3().configureCompiler(config);
  1750. return TestBedRender3;
  1751. };
  1752. /**
  1753. * Allows overriding default providers, directives, pipes, modules of the test injector,
  1754. * which are defined in test_injector.js
  1755. */
  1756. TestBedRender3.configureTestingModule = function (moduleDef) {
  1757. _getTestBedRender3().configureTestingModule(moduleDef);
  1758. return TestBedRender3;
  1759. };
  1760. /**
  1761. * Compile components with a `templateUrl` for the test's NgModule.
  1762. * It is necessary to call this function
  1763. * as fetching urls is asynchronous.
  1764. */
  1765. TestBedRender3.compileComponents = function () { return _getTestBedRender3().compileComponents(); };
  1766. TestBedRender3.overrideModule = function (ngModule, override) {
  1767. _getTestBedRender3().overrideModule(ngModule, override);
  1768. return TestBedRender3;
  1769. };
  1770. TestBedRender3.overrideComponent = function (component, override) {
  1771. _getTestBedRender3().overrideComponent(component, override);
  1772. return TestBedRender3;
  1773. };
  1774. TestBedRender3.overrideDirective = function (directive, override) {
  1775. _getTestBedRender3().overrideDirective(directive, override);
  1776. return TestBedRender3;
  1777. };
  1778. TestBedRender3.overridePipe = function (pipe, override) {
  1779. _getTestBedRender3().overridePipe(pipe, override);
  1780. return TestBedRender3;
  1781. };
  1782. TestBedRender3.overrideTemplate = function (component, template) {
  1783. _getTestBedRender3().overrideComponent(component, { set: { template: template, templateUrl: null } });
  1784. return TestBedRender3;
  1785. };
  1786. /**
  1787. * Overrides the template of the given component, compiling the template
  1788. * in the context of the TestingModule.
  1789. *
  1790. * Note: This works for JIT and AOTed components as well.
  1791. */
  1792. TestBedRender3.overrideTemplateUsingTestingModule = function (component, template) {
  1793. _getTestBedRender3().overrideTemplateUsingTestingModule(component, template);
  1794. return TestBedRender3;
  1795. };
  1796. TestBedRender3.overrideProvider = function (token, provider) {
  1797. _getTestBedRender3().overrideProvider(token, provider);
  1798. return TestBedRender3;
  1799. };
  1800. TestBedRender3.get = function (token, notFoundValue, flags) {
  1801. if (notFoundValue === void 0) { notFoundValue = Injector.THROW_IF_NOT_FOUND; }
  1802. if (flags === void 0) { flags = InjectFlags.Default; }
  1803. return _getTestBedRender3().get(token, notFoundValue);
  1804. };
  1805. TestBedRender3.createComponent = function (component) {
  1806. return _getTestBedRender3().createComponent(component);
  1807. };
  1808. TestBedRender3.resetTestingModule = function () {
  1809. _getTestBedRender3().resetTestingModule();
  1810. return TestBedRender3;
  1811. };
  1812. /**
  1813. * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
  1814. * angular module. These are common to every test in the suite.
  1815. *
  1816. * This may only be called once, to set up the common providers for the current test
  1817. * suite on the current platform. If you absolutely need to change the providers,
  1818. * first use `resetTestEnvironment`.
  1819. *
  1820. * Test modules and platforms for individual platforms are available from
  1821. * '@angular/<platform_name>/testing'.
  1822. *
  1823. * @publicApi
  1824. */
  1825. TestBedRender3.prototype.initTestEnvironment = function (ngModule, platform, aotSummaries) {
  1826. if (this.platform || this.ngModule) {
  1827. throw new Error('Cannot set base providers because it has already been called');
  1828. }
  1829. this.platform = platform;
  1830. this.ngModule = ngModule;
  1831. this._compiler = new R3TestBedCompiler(this.platform, this.ngModule);
  1832. };
  1833. /**
  1834. * Reset the providers for the test injector.
  1835. *
  1836. * @publicApi
  1837. */
  1838. TestBedRender3.prototype.resetTestEnvironment = function () {
  1839. this.resetTestingModule();
  1840. this._compiler = null;
  1841. this.platform = null;
  1842. this.ngModule = null;
  1843. };
  1844. TestBedRender3.prototype.resetTestingModule = function () {
  1845. this.checkGlobalCompilationFinished();
  1846. ɵresetCompiledComponents();
  1847. if (this._compiler !== null) {
  1848. this.compiler.restoreOriginalState();
  1849. }
  1850. this._compiler = new R3TestBedCompiler(this.platform, this.ngModule);
  1851. this._testModuleRef = null;
  1852. this.destroyActiveFixtures();
  1853. };
  1854. TestBedRender3.prototype.configureCompiler = function (config) {
  1855. if (config.useJit != null) {
  1856. throw new Error('the Render3 compiler JiT mode is not configurable !');
  1857. }
  1858. if (config.providers !== undefined) {
  1859. this.compiler.setCompilerProviders(config.providers);
  1860. }
  1861. };
  1862. TestBedRender3.prototype.configureTestingModule = function (moduleDef) {
  1863. this.assertNotInstantiated('R3TestBed.configureTestingModule', 'configure the test module');
  1864. this.compiler.configureTestingModule(moduleDef);
  1865. };
  1866. TestBedRender3.prototype.compileComponents = function () { return this.compiler.compileComponents(); };
  1867. TestBedRender3.prototype.get = function (token, notFoundValue, flags) {
  1868. if (notFoundValue === void 0) { notFoundValue = Injector.THROW_IF_NOT_FOUND; }
  1869. if (flags === void 0) { flags = InjectFlags.Default; }
  1870. if (token === TestBedRender3) {
  1871. return this;
  1872. }
  1873. var result = this.testModuleRef.injector.get(token, UNDEFINED, flags);
  1874. return result === UNDEFINED ? this.compiler.injector.get(token, notFoundValue, flags) : result;
  1875. };
  1876. TestBedRender3.prototype.execute = function (tokens, fn, context) {
  1877. var _this = this;
  1878. var params = tokens.map(function (t) { return _this.get(t); });
  1879. return fn.apply(context, params);
  1880. };
  1881. TestBedRender3.prototype.overrideModule = function (ngModule, override) {
  1882. this.assertNotInstantiated('overrideModule', 'override module metadata');
  1883. this.compiler.overrideModule(ngModule, override);
  1884. };
  1885. TestBedRender3.prototype.overrideComponent = function (component, override) {
  1886. this.assertNotInstantiated('overrideComponent', 'override component metadata');
  1887. this.compiler.overrideComponent(component, override);
  1888. };
  1889. TestBedRender3.prototype.overrideTemplateUsingTestingModule = function (component, template) {
  1890. this.assertNotInstantiated('R3TestBed.overrideTemplateUsingTestingModule', 'Cannot override template when the test module has already been instantiated');
  1891. this.compiler.overrideTemplateUsingTestingModule(component, template);
  1892. };
  1893. TestBedRender3.prototype.overrideDirective = function (directive, override) {
  1894. this.assertNotInstantiated('overrideDirective', 'override directive metadata');
  1895. this.compiler.overrideDirective(directive, override);
  1896. };
  1897. TestBedRender3.prototype.overridePipe = function (pipe, override) {
  1898. this.assertNotInstantiated('overridePipe', 'override pipe metadata');
  1899. this.compiler.overridePipe(pipe, override);
  1900. };
  1901. /**
  1902. * Overwrites all providers for the given token with the given provider definition.
  1903. */
  1904. TestBedRender3.prototype.overrideProvider = function (token, provider) {
  1905. this.compiler.overrideProvider(token, provider);
  1906. };
  1907. TestBedRender3.prototype.createComponent = function (type) {
  1908. var _this = this;
  1909. var testComponentRenderer = this.get(TestComponentRenderer);
  1910. var rootElId = "root-ng-internal-isolated-" + _nextRootElementId++;
  1911. testComponentRenderer.insertRootElement(rootElId);
  1912. var componentDef = type.ngComponentDef;
  1913. if (!componentDef) {
  1914. throw new Error("It looks like '" + ɵstringify(type) + "' has not been IVY compiled - it has no 'ngComponentDef' field");
  1915. }
  1916. // TODO: Don't cast as `any`, proper type is boolean[]
  1917. var noNgZone = this.get(ComponentFixtureNoNgZone, false);
  1918. // TODO: Don't cast as `any`, proper type is boolean[]
  1919. var autoDetect = this.get(ComponentFixtureAutoDetect, false);
  1920. var ngZone = noNgZone ? null : this.get(NgZone, null);
  1921. var componentFactory = new ɵRender3ComponentFactory(componentDef);
  1922. var initComponent = function () {
  1923. var componentRef = componentFactory.create(Injector.NULL, [], "#" + rootElId, _this.testModuleRef);
  1924. return new ComponentFixture(componentRef, ngZone, autoDetect);
  1925. };
  1926. var fixture = ngZone ? ngZone.run(initComponent) : initComponent();
  1927. this._activeFixtures.push(fixture);
  1928. return fixture;
  1929. };
  1930. Object.defineProperty(TestBedRender3.prototype, "compiler", {
  1931. get: function () {
  1932. if (this._compiler === null) {
  1933. throw new Error("Need to call TestBed.initTestEnvironment() first");
  1934. }
  1935. return this._compiler;
  1936. },
  1937. enumerable: true,
  1938. configurable: true
  1939. });
  1940. Object.defineProperty(TestBedRender3.prototype, "testModuleRef", {
  1941. get: function () {
  1942. if (this._testModuleRef === null) {
  1943. this._testModuleRef = this.compiler.finalize();
  1944. }
  1945. return this._testModuleRef;
  1946. },
  1947. enumerable: true,
  1948. configurable: true
  1949. });
  1950. TestBedRender3.prototype.assertNotInstantiated = function (methodName, methodDescription) {
  1951. if (this._testModuleRef !== null) {
  1952. throw new Error("Cannot " + methodDescription + " when the test module has already been instantiated. " +
  1953. ("Make sure you are not using `inject` before `" + methodName + "`."));
  1954. }
  1955. };
  1956. /**
  1957. * Check whether the module scoping queue should be flushed, and flush it if needed.
  1958. *
  1959. * When the TestBed is reset, it clears the JIT module compilation queue, cancelling any
  1960. * in-progress module compilation. This creates a potential hazard - the very first time the
  1961. * TestBed is initialized (or if it's reset without being initialized), there may be pending
  1962. * compilations of modules declared in global scope. These compilations should be finished.
  1963. *
  1964. * To ensure that globally declared modules have their components scoped properly, this function
  1965. * is called whenever TestBed is initialized or reset. The _first_ time that this happens, prior
  1966. * to any other operations, the scoping queue is flushed.
  1967. */
  1968. TestBedRender3.prototype.checkGlobalCompilationFinished = function () {
  1969. // Checking _testNgModuleRef is null should not be necessary, but is left in as an additional
  1970. // guard that compilations queued in tests (after instantiation) are never flushed accidentally.
  1971. if (!this._globalCompilationChecked && this._testModuleRef === null) {
  1972. ɵflushModuleScopingQueueAsMuchAsPossible();
  1973. }
  1974. this._globalCompilationChecked = true;
  1975. };
  1976. TestBedRender3.prototype.destroyActiveFixtures = function () {
  1977. this._activeFixtures.forEach(function (fixture) {
  1978. try {
  1979. fixture.destroy();
  1980. }
  1981. catch (e) {
  1982. console.error('Error during cleanup of component', {
  1983. component: fixture.componentInstance,
  1984. stacktrace: e,
  1985. });
  1986. }
  1987. });
  1988. this._activeFixtures = [];
  1989. };
  1990. return TestBedRender3;
  1991. }());
  1992. var testBed;
  1993. function _getTestBedRender3() {
  1994. return testBed = testBed || new TestBedRender3();
  1995. }
  1996. /**
  1997. * @license
  1998. * Copyright Google Inc. All Rights Reserved.
  1999. *
  2000. * Use of this source code is governed by an MIT-style license that can be
  2001. * found in the LICENSE file at https://angular.io/license
  2002. */
  2003. function unimplemented() {
  2004. throw Error('unimplemented');
  2005. }
  2006. /**
  2007. * Special interface to the compiler only used by testing
  2008. *
  2009. * @publicApi
  2010. */
  2011. var TestingCompiler = /** @class */ (function (_super) {
  2012. __extends(TestingCompiler, _super);
  2013. function TestingCompiler() {
  2014. return _super !== null && _super.apply(this, arguments) || this;
  2015. }
  2016. Object.defineProperty(TestingCompiler.prototype, "injector", {
  2017. get: function () { throw unimplemented(); },
  2018. enumerable: true,
  2019. configurable: true
  2020. });
  2021. TestingCompiler.prototype.overrideModule = function (module, overrides) {
  2022. throw unimplemented();
  2023. };
  2024. TestingCompiler.prototype.overrideDirective = function (directive, overrides) {
  2025. throw unimplemented();
  2026. };
  2027. TestingCompiler.prototype.overrideComponent = function (component, overrides) {
  2028. throw unimplemented();
  2029. };
  2030. TestingCompiler.prototype.overridePipe = function (directive, overrides) {
  2031. throw unimplemented();
  2032. };
  2033. /**
  2034. * Allows to pass the compile summary from AOT compilation to the JIT compiler,
  2035. * so that it can use the code generated by AOT.
  2036. */
  2037. TestingCompiler.prototype.loadAotSummaries = function (summaries) { throw unimplemented(); };
  2038. /**
  2039. * Gets the component factory for the given component.
  2040. * This assumes that the component has been compiled before calling this call using
  2041. * `compileModuleAndAllComponents*`.
  2042. */
  2043. TestingCompiler.prototype.getComponentFactory = function (component) { throw unimplemented(); };
  2044. /**
  2045. * Returns the component type that is stored in the given error.
  2046. * This can be used for errors created by compileModule...
  2047. */
  2048. TestingCompiler.prototype.getComponentFromError = function (error) { throw unimplemented(); };
  2049. TestingCompiler = __decorate([
  2050. Injectable()
  2051. ], TestingCompiler);
  2052. return TestingCompiler;
  2053. }(Compiler));
  2054. /**
  2055. * A factory for creating a Compiler
  2056. *
  2057. * @publicApi
  2058. */
  2059. var TestingCompilerFactory = /** @class */ (function () {
  2060. function TestingCompilerFactory() {
  2061. }
  2062. return TestingCompilerFactory;
  2063. }());
  2064. /**
  2065. * @license
  2066. * Copyright Google Inc. All Rights Reserved.
  2067. *
  2068. * Use of this source code is governed by an MIT-style license that can be
  2069. * found in the LICENSE file at https://angular.io/license
  2070. */
  2071. var UNDEFINED$1 = new Object();
  2072. var _nextRootElementId$1 = 0;
  2073. /**
  2074. * @description
  2075. * Configures and initializes environment for unit testing and provides methods for
  2076. * creating components and services in unit tests.
  2077. *
  2078. * `TestBed` is the primary api for writing unit tests for Angular applications and libraries.
  2079. *
  2080. * Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
  2081. * according to the compiler used.
  2082. */
  2083. var TestBedViewEngine = /** @class */ (function () {
  2084. function TestBedViewEngine() {
  2085. this._instantiated = false;
  2086. this._compiler = null;
  2087. this._moduleRef = null;
  2088. this._moduleFactory = null;
  2089. this._compilerOptions = [];
  2090. this._moduleOverrides = [];
  2091. this._componentOverrides = [];
  2092. this._directiveOverrides = [];
  2093. this._pipeOverrides = [];
  2094. this._providers = [];
  2095. this._declarations = [];
  2096. this._imports = [];
  2097. this._schemas = [];
  2098. this._activeFixtures = [];
  2099. this._testEnvAotSummaries = function () { return []; };
  2100. this._aotSummaries = [];
  2101. this._templateOverrides = [];
  2102. this._isRoot = true;
  2103. this._rootProviderOverrides = [];
  2104. this.platform = null;
  2105. this.ngModule = null;
  2106. }
  2107. /**
  2108. * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
  2109. * angular module. These are common to every test in the suite.
  2110. *
  2111. * This may only be called once, to set up the common providers for the current test
  2112. * suite on the current platform. If you absolutely need to change the providers,
  2113. * first use `resetTestEnvironment`.
  2114. *
  2115. * Test modules and platforms for individual platforms are available from
  2116. * '@angular/<platform_name>/testing'.
  2117. */
  2118. TestBedViewEngine.initTestEnvironment = function (ngModule, platform, aotSummaries) {
  2119. var testBed = _getTestBedViewEngine();
  2120. testBed.initTestEnvironment(ngModule, platform, aotSummaries);
  2121. return testBed;
  2122. };
  2123. /**
  2124. * Reset the providers for the test injector.
  2125. */
  2126. TestBedViewEngine.resetTestEnvironment = function () { _getTestBedViewEngine().resetTestEnvironment(); };
  2127. TestBedViewEngine.resetTestingModule = function () {
  2128. _getTestBedViewEngine().resetTestingModule();
  2129. return TestBedViewEngine;
  2130. };
  2131. /**
  2132. * Allows overriding default compiler providers and settings
  2133. * which are defined in test_injector.js
  2134. */
  2135. TestBedViewEngine.configureCompiler = function (config) {
  2136. _getTestBedViewEngine().configureCompiler(config);
  2137. return TestBedViewEngine;
  2138. };
  2139. /**
  2140. * Allows overriding default providers, directives, pipes, modules of the test injector,
  2141. * which are defined in test_injector.js
  2142. */
  2143. TestBedViewEngine.configureTestingModule = function (moduleDef) {
  2144. _getTestBedViewEngine().configureTestingModule(moduleDef);
  2145. return TestBedViewEngine;
  2146. };
  2147. /**
  2148. * Compile components with a `templateUrl` for the test's NgModule.
  2149. * It is necessary to call this function
  2150. * as fetching urls is asynchronous.
  2151. */
  2152. TestBedViewEngine.compileComponents = function () { return getTestBed().compileComponents(); };
  2153. TestBedViewEngine.overrideModule = function (ngModule, override) {
  2154. _getTestBedViewEngine().overrideModule(ngModule, override);
  2155. return TestBedViewEngine;
  2156. };
  2157. TestBedViewEngine.overrideComponent = function (component, override) {
  2158. _getTestBedViewEngine().overrideComponent(component, override);
  2159. return TestBedViewEngine;
  2160. };
  2161. TestBedViewEngine.overrideDirective = function (directive, override) {
  2162. _getTestBedViewEngine().overrideDirective(directive, override);
  2163. return TestBedViewEngine;
  2164. };
  2165. TestBedViewEngine.overridePipe = function (pipe, override) {
  2166. _getTestBedViewEngine().overridePipe(pipe, override);
  2167. return TestBedViewEngine;
  2168. };
  2169. TestBedViewEngine.overrideTemplate = function (component, template) {
  2170. _getTestBedViewEngine().overrideComponent(component, { set: { template: template, templateUrl: null } });
  2171. return TestBedViewEngine;
  2172. };
  2173. /**
  2174. * Overrides the template of the given component, compiling the template
  2175. * in the context of the TestingModule.
  2176. *
  2177. * Note: This works for JIT and AOTed components as well.
  2178. */
  2179. TestBedViewEngine.overrideTemplateUsingTestingModule = function (component, template) {
  2180. _getTestBedViewEngine().overrideTemplateUsingTestingModule(component, template);
  2181. return TestBedViewEngine;
  2182. };
  2183. TestBedViewEngine.overrideProvider = function (token, provider) {
  2184. _getTestBedViewEngine().overrideProvider(token, provider);
  2185. return TestBedViewEngine;
  2186. };
  2187. TestBedViewEngine.get = function (token, notFoundValue, flags) {
  2188. if (notFoundValue === void 0) { notFoundValue = Injector.THROW_IF_NOT_FOUND; }
  2189. if (flags === void 0) { flags = InjectFlags.Default; }
  2190. return _getTestBedViewEngine().get(token, notFoundValue, flags);
  2191. };
  2192. TestBedViewEngine.createComponent = function (component) {
  2193. return _getTestBedViewEngine().createComponent(component);
  2194. };
  2195. /**
  2196. * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
  2197. * angular module. These are common to every test in the suite.
  2198. *
  2199. * This may only be called once, to set up the common providers for the current test
  2200. * suite on the current platform. If you absolutely need to change the providers,
  2201. * first use `resetTestEnvironment`.
  2202. *
  2203. * Test modules and platforms for individual platforms are available from
  2204. * '@angular/<platform_name>/testing'.
  2205. */
  2206. TestBedViewEngine.prototype.initTestEnvironment = function (ngModule, platform, aotSummaries) {
  2207. if (this.platform || this.ngModule) {
  2208. throw new Error('Cannot set base providers because it has already been called');
  2209. }
  2210. this.platform = platform;
  2211. this.ngModule = ngModule;
  2212. if (aotSummaries) {
  2213. this._testEnvAotSummaries = aotSummaries;
  2214. }
  2215. };
  2216. /**
  2217. * Reset the providers for the test injector.
  2218. */
  2219. TestBedViewEngine.prototype.resetTestEnvironment = function () {
  2220. this.resetTestingModule();
  2221. this.platform = null;
  2222. this.ngModule = null;
  2223. this._testEnvAotSummaries = function () { return []; };
  2224. };
  2225. TestBedViewEngine.prototype.resetTestingModule = function () {
  2226. ɵclearOverrides();
  2227. this._aotSummaries = [];
  2228. this._templateOverrides = [];
  2229. this._compiler = null;
  2230. this._moduleOverrides = [];
  2231. this._componentOverrides = [];
  2232. this._directiveOverrides = [];
  2233. this._pipeOverrides = [];
  2234. this._isRoot = true;
  2235. this._rootProviderOverrides = [];
  2236. this._moduleRef = null;
  2237. this._moduleFactory = null;
  2238. this._compilerOptions = [];
  2239. this._providers = [];
  2240. this._declarations = [];
  2241. this._imports = [];
  2242. this._schemas = [];
  2243. this._instantiated = false;
  2244. this._activeFixtures.forEach(function (fixture) {
  2245. try {
  2246. fixture.destroy();
  2247. }
  2248. catch (e) {
  2249. console.error('Error during cleanup of component', {
  2250. component: fixture.componentInstance,
  2251. stacktrace: e,
  2252. });
  2253. }
  2254. });
  2255. this._activeFixtures = [];
  2256. };
  2257. TestBedViewEngine.prototype.configureCompiler = function (config) {
  2258. this._assertNotInstantiated('TestBed.configureCompiler', 'configure the compiler');
  2259. this._compilerOptions.push(config);
  2260. };
  2261. TestBedViewEngine.prototype.configureTestingModule = function (moduleDef) {
  2262. var _a, _b, _c, _d;
  2263. this._assertNotInstantiated('TestBed.configureTestingModule', 'configure the test module');
  2264. if (moduleDef.providers) {
  2265. (_a = this._providers).push.apply(_a, __spread(moduleDef.providers));
  2266. }
  2267. if (moduleDef.declarations) {
  2268. (_b = this._declarations).push.apply(_b, __spread(moduleDef.declarations));
  2269. }
  2270. if (moduleDef.imports) {
  2271. (_c = this._imports).push.apply(_c, __spread(moduleDef.imports));
  2272. }
  2273. if (moduleDef.schemas) {
  2274. (_d = this._schemas).push.apply(_d, __spread(moduleDef.schemas));
  2275. }
  2276. if (moduleDef.aotSummaries) {
  2277. this._aotSummaries.push(moduleDef.aotSummaries);
  2278. }
  2279. };
  2280. TestBedViewEngine.prototype.compileComponents = function () {
  2281. var _this = this;
  2282. if (this._moduleFactory || this._instantiated) {
  2283. return Promise.resolve(null);
  2284. }
  2285. var moduleType = this._createCompilerAndModule();
  2286. return this._compiler.compileModuleAndAllComponentsAsync(moduleType)
  2287. .then(function (moduleAndComponentFactories) {
  2288. _this._moduleFactory = moduleAndComponentFactories.ngModuleFactory;
  2289. });
  2290. };
  2291. TestBedViewEngine.prototype._initIfNeeded = function () {
  2292. var e_1, _a;
  2293. if (this._instantiated) {
  2294. return;
  2295. }
  2296. if (!this._moduleFactory) {
  2297. try {
  2298. var moduleType = this._createCompilerAndModule();
  2299. this._moduleFactory =
  2300. this._compiler.compileModuleAndAllComponentsSync(moduleType).ngModuleFactory;
  2301. }
  2302. catch (e) {
  2303. var errorCompType = this._compiler.getComponentFromError(e);
  2304. if (errorCompType) {
  2305. throw new Error("This test module uses the component " + ɵstringify(errorCompType) + " which is using a \"templateUrl\" or \"styleUrls\", but they were never compiled. " +
  2306. "Please call \"TestBed.compileComponents\" before your test.");
  2307. }
  2308. else {
  2309. throw e;
  2310. }
  2311. }
  2312. }
  2313. try {
  2314. for (var _b = __values(this._templateOverrides), _c = _b.next(); !_c.done; _c = _b.next()) {
  2315. var _d = _c.value, component = _d.component, templateOf = _d.templateOf;
  2316. var compFactory = this._compiler.getComponentFactory(templateOf);
  2317. ɵoverrideComponentView(component, compFactory);
  2318. }
  2319. }
  2320. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  2321. finally {
  2322. try {
  2323. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  2324. }
  2325. finally { if (e_1) throw e_1.error; }
  2326. }
  2327. var ngZone = new NgZone({ enableLongStackTrace: true });
  2328. var providers = [{ provide: NgZone, useValue: ngZone }];
  2329. var ngZoneInjector = Injector.create({
  2330. providers: providers,
  2331. parent: this.platform.injector,
  2332. name: this._moduleFactory.moduleType.name
  2333. });
  2334. this._moduleRef = this._moduleFactory.create(ngZoneInjector);
  2335. // ApplicationInitStatus.runInitializers() is marked @internal to core. So casting to any
  2336. // before accessing it.
  2337. this._moduleRef.injector.get(ApplicationInitStatus).runInitializers();
  2338. this._instantiated = true;
  2339. };
  2340. TestBedViewEngine.prototype._createCompilerAndModule = function () {
  2341. var _this = this;
  2342. var e_2, _a;
  2343. var providers = this._providers.concat([{ provide: TestBed, useValue: this }]);
  2344. var declarations = __spread(this._declarations, this._templateOverrides.map(function (entry) { return entry.templateOf; }));
  2345. var rootScopeImports = [];
  2346. var rootProviderOverrides = this._rootProviderOverrides;
  2347. if (this._isRoot) {
  2348. var RootScopeModule = /** @class */ (function () {
  2349. function RootScopeModule() {
  2350. }
  2351. RootScopeModule = __decorate([
  2352. NgModule({
  2353. providers: __spread(rootProviderOverrides),
  2354. jit: true,
  2355. })
  2356. ], RootScopeModule);
  2357. return RootScopeModule;
  2358. }());
  2359. rootScopeImports.push(RootScopeModule);
  2360. }
  2361. providers.push({ provide: ɵAPP_ROOT, useValue: this._isRoot });
  2362. var imports = [rootScopeImports, this.ngModule, this._imports];
  2363. var schemas = this._schemas;
  2364. var DynamicTestModule = /** @class */ (function () {
  2365. function DynamicTestModule() {
  2366. }
  2367. DynamicTestModule = __decorate([
  2368. NgModule({ providers: providers, declarations: declarations, imports: imports, schemas: schemas, jit: true })
  2369. ], DynamicTestModule);
  2370. return DynamicTestModule;
  2371. }());
  2372. var compilerFactory = this.platform.injector.get(TestingCompilerFactory);
  2373. this._compiler = compilerFactory.createTestingCompiler(this._compilerOptions);
  2374. try {
  2375. for (var _b = __values(__spread([this._testEnvAotSummaries], this._aotSummaries)), _c = _b.next(); !_c.done; _c = _b.next()) {
  2376. var summary = _c.value;
  2377. this._compiler.loadAotSummaries(summary);
  2378. }
  2379. }
  2380. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  2381. finally {
  2382. try {
  2383. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  2384. }
  2385. finally { if (e_2) throw e_2.error; }
  2386. }
  2387. this._moduleOverrides.forEach(function (entry) { return _this._compiler.overrideModule(entry[0], entry[1]); });
  2388. this._componentOverrides.forEach(function (entry) { return _this._compiler.overrideComponent(entry[0], entry[1]); });
  2389. this._directiveOverrides.forEach(function (entry) { return _this._compiler.overrideDirective(entry[0], entry[1]); });
  2390. this._pipeOverrides.forEach(function (entry) { return _this._compiler.overridePipe(entry[0], entry[1]); });
  2391. return DynamicTestModule;
  2392. };
  2393. TestBedViewEngine.prototype._assertNotInstantiated = function (methodName, methodDescription) {
  2394. if (this._instantiated) {
  2395. throw new Error("Cannot " + methodDescription + " when the test module has already been instantiated. " +
  2396. ("Make sure you are not using `inject` before `" + methodName + "`."));
  2397. }
  2398. };
  2399. TestBedViewEngine.prototype.get = function (token, notFoundValue, flags) {
  2400. if (notFoundValue === void 0) { notFoundValue = Injector.THROW_IF_NOT_FOUND; }
  2401. if (flags === void 0) { flags = InjectFlags.Default; }
  2402. this._initIfNeeded();
  2403. if (token === TestBed) {
  2404. return this;
  2405. }
  2406. // Tests can inject things from the ng module and from the compiler,
  2407. // but the ng module can't inject things from the compiler and vice versa.
  2408. var result = this._moduleRef.injector.get(token, UNDEFINED$1, flags);
  2409. return result === UNDEFINED$1 ? this._compiler.injector.get(token, notFoundValue, flags) : result;
  2410. };
  2411. TestBedViewEngine.prototype.execute = function (tokens, fn, context) {
  2412. var _this = this;
  2413. this._initIfNeeded();
  2414. var params = tokens.map(function (t) { return _this.get(t); });
  2415. return fn.apply(context, params);
  2416. };
  2417. TestBedViewEngine.prototype.overrideModule = function (ngModule, override) {
  2418. this._assertNotInstantiated('overrideModule', 'override module metadata');
  2419. this._moduleOverrides.push([ngModule, override]);
  2420. };
  2421. TestBedViewEngine.prototype.overrideComponent = function (component, override) {
  2422. this._assertNotInstantiated('overrideComponent', 'override component metadata');
  2423. this._componentOverrides.push([component, override]);
  2424. };
  2425. TestBedViewEngine.prototype.overrideDirective = function (directive, override) {
  2426. this._assertNotInstantiated('overrideDirective', 'override directive metadata');
  2427. this._directiveOverrides.push([directive, override]);
  2428. };
  2429. TestBedViewEngine.prototype.overridePipe = function (pipe, override) {
  2430. this._assertNotInstantiated('overridePipe', 'override pipe metadata');
  2431. this._pipeOverrides.push([pipe, override]);
  2432. };
  2433. TestBedViewEngine.prototype.overrideProvider = function (token, provider) {
  2434. this.overrideProviderImpl(token, provider);
  2435. };
  2436. TestBedViewEngine.prototype.overrideProviderImpl = function (token, provider, deprecated) {
  2437. if (deprecated === void 0) { deprecated = false; }
  2438. var def = null;
  2439. if (typeof token !== 'string' && (def = ɵgetInjectableDef(token)) && def.providedIn === 'root') {
  2440. if (provider.useFactory) {
  2441. this._rootProviderOverrides.push({ provide: token, useFactory: provider.useFactory, deps: provider.deps || [] });
  2442. }
  2443. else {
  2444. this._rootProviderOverrides.push({ provide: token, useValue: provider.useValue });
  2445. }
  2446. }
  2447. var flags = 0;
  2448. var value;
  2449. if (provider.useFactory) {
  2450. flags |= 1024 /* TypeFactoryProvider */;
  2451. value = provider.useFactory;
  2452. }
  2453. else {
  2454. flags |= 256 /* TypeValueProvider */;
  2455. value = provider.useValue;
  2456. }
  2457. var deps = (provider.deps || []).map(function (dep) {
  2458. var depFlags = 0 /* None */;
  2459. var depToken;
  2460. if (Array.isArray(dep)) {
  2461. dep.forEach(function (entry) {
  2462. if (entry instanceof Optional) {
  2463. depFlags |= 2 /* Optional */;
  2464. }
  2465. else if (entry instanceof SkipSelf) {
  2466. depFlags |= 1 /* SkipSelf */;
  2467. }
  2468. else {
  2469. depToken = entry;
  2470. }
  2471. });
  2472. }
  2473. else {
  2474. depToken = dep;
  2475. }
  2476. return [depFlags, depToken];
  2477. });
  2478. ɵoverrideProvider({ token: token, flags: flags, deps: deps, value: value, deprecatedBehavior: deprecated });
  2479. };
  2480. TestBedViewEngine.prototype.overrideTemplateUsingTestingModule = function (component, template) {
  2481. this._assertNotInstantiated('overrideTemplateUsingTestingModule', 'override template');
  2482. var OverrideComponent = /** @class */ (function () {
  2483. function OverrideComponent() {
  2484. }
  2485. OverrideComponent = __decorate([
  2486. Component({ selector: 'empty', template: template, jit: true })
  2487. ], OverrideComponent);
  2488. return OverrideComponent;
  2489. }());
  2490. this._templateOverrides.push({ component: component, templateOf: OverrideComponent });
  2491. };
  2492. TestBedViewEngine.prototype.createComponent = function (component) {
  2493. var _this = this;
  2494. this._initIfNeeded();
  2495. var componentFactory = this._compiler.getComponentFactory(component);
  2496. if (!componentFactory) {
  2497. throw new Error("Cannot create the component " + ɵstringify(component) + " as it was not imported into the testing module!");
  2498. }
  2499. // TODO: Don't cast as `any`, proper type is boolean[]
  2500. var noNgZone = this.get(ComponentFixtureNoNgZone, false);
  2501. // TODO: Don't cast as `any`, proper type is boolean[]
  2502. var autoDetect = this.get(ComponentFixtureAutoDetect, false);
  2503. var ngZone = noNgZone ? null : this.get(NgZone, null);
  2504. var testComponentRenderer = this.get(TestComponentRenderer);
  2505. var rootElId = "root" + _nextRootElementId$1++;
  2506. testComponentRenderer.insertRootElement(rootElId);
  2507. var initComponent = function () {
  2508. var componentRef = componentFactory.create(Injector.NULL, [], "#" + rootElId, _this._moduleRef);
  2509. return new ComponentFixture(componentRef, ngZone, autoDetect);
  2510. };
  2511. var fixture = !ngZone ? initComponent() : ngZone.run(initComponent);
  2512. this._activeFixtures.push(fixture);
  2513. return fixture;
  2514. };
  2515. return TestBedViewEngine;
  2516. }());
  2517. /**
  2518. * @description
  2519. * Configures and initializes environment for unit testing and provides methods for
  2520. * creating components and services in unit tests.
  2521. *
  2522. * `TestBed` is the primary api for writing unit tests for Angular applications and libraries.
  2523. *
  2524. * Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
  2525. * according to the compiler used.
  2526. *
  2527. * @publicApi
  2528. */
  2529. var TestBed = ɵivyEnabled ? TestBedRender3 : TestBedViewEngine;
  2530. /**
  2531. * Returns a singleton of the applicable `TestBed`.
  2532. *
  2533. * It will be either an instance of `TestBedViewEngine` or `TestBedRender3`.
  2534. *
  2535. * @publicApi
  2536. */
  2537. var getTestBed = ɵivyEnabled ? _getTestBedRender3 : _getTestBedViewEngine;
  2538. var testBed$1;
  2539. function _getTestBedViewEngine() {
  2540. return testBed$1 = testBed$1 || new TestBedViewEngine();
  2541. }
  2542. /**
  2543. * Allows injecting dependencies in `beforeEach()` and `it()`.
  2544. *
  2545. * Example:
  2546. *
  2547. * ```
  2548. * beforeEach(inject([Dependency, AClass], (dep, object) => {
  2549. * // some code that uses `dep` and `object`
  2550. * // ...
  2551. * }));
  2552. *
  2553. * it('...', inject([AClass], (object) => {
  2554. * object.doSomething();
  2555. * expect(...);
  2556. * })
  2557. * ```
  2558. *
  2559. * Notes:
  2560. * - inject is currently a function because of some Traceur limitation the syntax should
  2561. * eventually
  2562. * becomes `it('...', @Inject (object: AClass, async: AsyncTestCompleter) => { ... });`
  2563. *
  2564. * @publicApi
  2565. */
  2566. function inject(tokens, fn) {
  2567. var testBed = getTestBed();
  2568. if (tokens.indexOf(AsyncTestCompleter) >= 0) {
  2569. // Not using an arrow function to preserve context passed from call site
  2570. return function () {
  2571. var _this = this;
  2572. // Return an async test method that returns a Promise if AsyncTestCompleter is one of
  2573. // the injected tokens.
  2574. return testBed.compileComponents().then(function () {
  2575. var completer = testBed.get(AsyncTestCompleter);
  2576. testBed.execute(tokens, fn, _this);
  2577. return completer.promise;
  2578. });
  2579. };
  2580. }
  2581. else {
  2582. // Not using an arrow function to preserve context passed from call site
  2583. return function () { return testBed.execute(tokens, fn, this); };
  2584. }
  2585. }
  2586. /**
  2587. * @publicApi
  2588. */
  2589. var InjectSetupWrapper = /** @class */ (function () {
  2590. function InjectSetupWrapper(_moduleDef) {
  2591. this._moduleDef = _moduleDef;
  2592. }
  2593. InjectSetupWrapper.prototype._addModule = function () {
  2594. var moduleDef = this._moduleDef();
  2595. if (moduleDef) {
  2596. getTestBed().configureTestingModule(moduleDef);
  2597. }
  2598. };
  2599. InjectSetupWrapper.prototype.inject = function (tokens, fn) {
  2600. var self = this;
  2601. // Not using an arrow function to preserve context passed from call site
  2602. return function () {
  2603. self._addModule();
  2604. return inject(tokens, fn).call(this);
  2605. };
  2606. };
  2607. return InjectSetupWrapper;
  2608. }());
  2609. function withModule(moduleDef, fn) {
  2610. if (fn) {
  2611. // Not using an arrow function to preserve context passed from call site
  2612. return function () {
  2613. var testBed = getTestBed();
  2614. if (moduleDef) {
  2615. testBed.configureTestingModule(moduleDef);
  2616. }
  2617. return fn.apply(this);
  2618. };
  2619. }
  2620. return new InjectSetupWrapper(function () { return moduleDef; });
  2621. }
  2622. /**
  2623. * @license
  2624. * Copyright Google Inc. All Rights Reserved.
  2625. *
  2626. * Use of this source code is governed by an MIT-style license that can be
  2627. * found in the LICENSE file at https://angular.io/license
  2628. */
  2629. var _global$1 = (typeof window === 'undefined' ? global : window);
  2630. // Reset the test providers and the fake async zone before each test.
  2631. if (_global$1.beforeEach) {
  2632. _global$1.beforeEach(function () {
  2633. TestBed.resetTestingModule();
  2634. resetFakeAsyncZone();
  2635. });
  2636. }
  2637. // TODO(juliemr): remove this, only used because we need to export something to have compilation
  2638. // work.
  2639. var __core_private_testing_placeholder__ = '';
  2640. /**
  2641. * @license
  2642. * Copyright Google Inc. All Rights Reserved.
  2643. *
  2644. * Use of this source code is governed by an MIT-style license that can be
  2645. * found in the LICENSE file at https://angular.io/license
  2646. */
  2647. /**
  2648. * @license
  2649. * Copyright Google Inc. All Rights Reserved.
  2650. *
  2651. * Use of this source code is governed by an MIT-style license that can be
  2652. * found in the LICENSE file at https://angular.io/license
  2653. */
  2654. /**
  2655. * @license
  2656. * Copyright Google Inc. All Rights Reserved.
  2657. *
  2658. * Use of this source code is governed by an MIT-style license that can be
  2659. * found in the LICENSE file at https://angular.io/license
  2660. */
  2661. // This file only reexports content of the `src` folder. Keep it that way.
  2662. /**
  2663. * @license
  2664. * Copyright Google Inc. All Rights Reserved.
  2665. *
  2666. * Use of this source code is governed by an MIT-style license that can be
  2667. * found in the LICENSE file at https://angular.io/license
  2668. */
  2669. /**
  2670. * Generated bundle index. Do not edit.
  2671. */
  2672. export { TestBedRender3 as ɵangular_packages_core_testing_testing_b, _getTestBedRender3 as ɵangular_packages_core_testing_testing_c, TestBedViewEngine as ɵangular_packages_core_testing_testing_a, TestBed, getTestBed, inject, InjectSetupWrapper, withModule, MetadataOverrider as ɵMetadataOverrider, async, ComponentFixture, resetFakeAsyncZone, fakeAsync, tick, flush, discardPeriodicTasks, flushMicrotasks, TestComponentRenderer, ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, __core_private_testing_placeholder__, TestingCompiler as ɵTestingCompiler, TestingCompilerFactory as ɵTestingCompilerFactory };
  2673. //# sourceMappingURL=testing.js.map