12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  1. /**
  2. * @license Angular v5.2.11
  3. * (c) 2010-2018 Google, Inc. https://angular.io/
  4. * License: MIT
  5. */
  6. import { ApplicationInitStatus, Compiler, Component, Injectable, InjectionToken, Injector, NgModule, NgZone, Optional, RendererFactory2, SkipSelf, getDebugNode, ɵclearOverrides, ɵoverrideComponentView, ɵoverrideProvider, ɵstringify } from '@angular/core';
  7. import { __extends } from 'tslib';
  8. /**
  9. * @license
  10. * Copyright Google Inc. All Rights Reserved.
  11. *
  12. * Use of this source code is governed by an MIT-style license that can be
  13. * found in the LICENSE file at https://angular.io/license
  14. */
  15. var _global = (typeof window === 'undefined' ? global : window);
  16. /**
  17. * Wraps a test function in an asynchronous test zone. The test will automatically
  18. * complete when all asynchronous calls within this zone are done. Can be used
  19. * to wrap an {@link inject} call.
  20. *
  21. * Example:
  22. *
  23. * ```
  24. * it('...', async(inject([AClass], (object) => {
  25. * object.doSomething.then(() => {
  26. * expect(...);
  27. * })
  28. * });
  29. * ```
  30. *
  31. * @stable
  32. */
  33. function async(fn) {
  34. // If we're running using the Jasmine test framework, adapt to call the 'done'
  35. // function when asynchronous activity is finished.
  36. if (_global.jasmine) {
  37. // Not using an arrow function to preserve context passed from call site
  38. return function (done) {
  39. if (!done) {
  40. // if we run beforeEach in @angular/core/testing/testing_internal then we get no done
  41. // fake it here and assume sync.
  42. done = function () { };
  43. done.fail = function (e) { throw e; };
  44. }
  45. runInTestZone(fn, this, done, function (err) {
  46. if (typeof err === 'string') {
  47. return done.fail(new Error(err));
  48. }
  49. else {
  50. done.fail(err);
  51. }
  52. });
  53. };
  54. }
  55. // Otherwise, return a promise which will resolve when asynchronous activity
  56. // is finished. This will be correctly consumed by the Mocha framework with
  57. // it('...', async(myFn)); or can be used in a custom framework.
  58. // Not using an arrow function to preserve context passed from call site
  59. return function () {
  60. var _this = this;
  61. return new Promise(function (finishCallback, failCallback) {
  62. runInTestZone(fn, _this, finishCallback, failCallback);
  63. });
  64. };
  65. }
  66. function runInTestZone(fn, context, finishCallback, failCallback) {
  67. var currentZone = Zone.current;
  68. var AsyncTestZoneSpec = Zone['AsyncTestZoneSpec'];
  69. if (AsyncTestZoneSpec === undefined) {
  70. throw new Error('AsyncTestZoneSpec is needed for the async() test helper but could not be found. ' +
  71. 'Please make sure that your environment includes zone.js/dist/async-test.js');
  72. }
  73. var ProxyZoneSpec = Zone['ProxyZoneSpec'];
  74. if (ProxyZoneSpec === undefined) {
  75. throw new Error('ProxyZoneSpec is needed for the async() test helper but could not be found. ' +
  76. 'Please make sure that your environment includes zone.js/dist/proxy.js');
  77. }
  78. var proxyZoneSpec = ProxyZoneSpec.get();
  79. ProxyZoneSpec.assertPresent();
  80. // We need to create the AsyncTestZoneSpec outside the ProxyZone.
  81. // If we do it in ProxyZone then we will get to infinite recursion.
  82. var proxyZone = Zone.current.getZoneWith('ProxyZoneSpec');
  83. var previousDelegate = proxyZoneSpec.getDelegate();
  84. proxyZone.parent.run(function () {
  85. var testZoneSpec = new AsyncTestZoneSpec(function () {
  86. // Need to restore the original zone.
  87. currentZone.run(function () {
  88. if (proxyZoneSpec.getDelegate() == testZoneSpec) {
  89. // Only reset the zone spec if it's sill this one. Otherwise, assume it's OK.
  90. proxyZoneSpec.setDelegate(previousDelegate);
  91. }
  92. finishCallback();
  93. });
  94. }, function (error) {
  95. // Need to restore the original zone.
  96. currentZone.run(function () {
  97. if (proxyZoneSpec.getDelegate() == testZoneSpec) {
  98. // Only reset the zone spec if it's sill this one. Otherwise, assume it's OK.
  99. proxyZoneSpec.setDelegate(previousDelegate);
  100. }
  101. failCallback(error);
  102. });
  103. }, 'test');
  104. proxyZoneSpec.setDelegate(testZoneSpec);
  105. });
  106. return Zone.current.runGuarded(fn, context);
  107. }
  108. /**
  109. * @license
  110. * Copyright Google Inc. All Rights Reserved.
  111. *
  112. * Use of this source code is governed by an MIT-style license that can be
  113. * found in the LICENSE file at https://angular.io/license
  114. */
  115. /**
  116. * Fixture for debugging and testing a component.
  117. *
  118. * @stable
  119. */
  120. var ComponentFixture = /** @class */ (function () {
  121. function ComponentFixture(componentRef, ngZone, _autoDetect) {
  122. var _this = this;
  123. this.componentRef = componentRef;
  124. this.ngZone = ngZone;
  125. this._autoDetect = _autoDetect;
  126. this._isStable = true;
  127. this._isDestroyed = false;
  128. this._resolve = null;
  129. this._promise = null;
  130. this._onUnstableSubscription = null;
  131. this._onStableSubscription = null;
  132. this._onMicrotaskEmptySubscription = null;
  133. this._onErrorSubscription = null;
  134. this.changeDetectorRef = componentRef.changeDetectorRef;
  135. this.elementRef = componentRef.location;
  136. this.debugElement = getDebugNode(this.elementRef.nativeElement);
  137. this.componentInstance = componentRef.instance;
  138. this.nativeElement = this.elementRef.nativeElement;
  139. this.componentRef = componentRef;
  140. this.ngZone = ngZone;
  141. if (ngZone) {
  142. // Create subscriptions outside the NgZone so that the callbacks run oustide
  143. // of NgZone.
  144. ngZone.runOutsideAngular(function () {
  145. _this._onUnstableSubscription =
  146. ngZone.onUnstable.subscribe({ next: function () { _this._isStable = false; } });
  147. _this._onMicrotaskEmptySubscription = ngZone.onMicrotaskEmpty.subscribe({
  148. next: function () {
  149. if (_this._autoDetect) {
  150. // Do a change detection run with checkNoChanges set to true to check
  151. // there are no changes on the second run.
  152. // Do a change detection run with checkNoChanges set to true to check
  153. // there are no changes on the second run.
  154. _this.detectChanges(true);
  155. }
  156. }
  157. });
  158. _this._onStableSubscription = ngZone.onStable.subscribe({
  159. next: function () {
  160. _this._isStable = true;
  161. // Check whether there is a pending whenStable() completer to resolve.
  162. if (_this._promise !== null) {
  163. // If so check whether there are no pending macrotasks before resolving.
  164. // Do this check in the next tick so that ngZone gets a chance to update the state of
  165. // pending macrotasks.
  166. scheduleMicroTask(function () {
  167. if (!ngZone.hasPendingMacrotasks) {
  168. if (_this._promise !== null) {
  169. _this._resolve(true);
  170. _this._resolve = null;
  171. _this._promise = null;
  172. }
  173. }
  174. });
  175. }
  176. }
  177. });
  178. _this._onErrorSubscription =
  179. ngZone.onError.subscribe({ next: function (error) { throw error; } });
  180. });
  181. }
  182. }
  183. ComponentFixture.prototype._tick = function (checkNoChanges) {
  184. this.changeDetectorRef.detectChanges();
  185. if (checkNoChanges) {
  186. this.checkNoChanges();
  187. }
  188. };
  189. /**
  190. * Trigger a change detection cycle for the component.
  191. */
  192. /**
  193. * Trigger a change detection cycle for the component.
  194. */
  195. ComponentFixture.prototype.detectChanges = /**
  196. * Trigger a change detection cycle for the component.
  197. */
  198. function (checkNoChanges) {
  199. var _this = this;
  200. if (checkNoChanges === void 0) { checkNoChanges = true; }
  201. if (this.ngZone != null) {
  202. // Run the change detection inside the NgZone so that any async tasks as part of the change
  203. // detection are captured by the zone and can be waited for in isStable.
  204. this.ngZone.run(function () { _this._tick(checkNoChanges); });
  205. }
  206. else {
  207. // Running without zone. Just do the change detection.
  208. this._tick(checkNoChanges);
  209. }
  210. };
  211. /**
  212. * Do a change detection run to make sure there were no changes.
  213. */
  214. /**
  215. * Do a change detection run to make sure there were no changes.
  216. */
  217. ComponentFixture.prototype.checkNoChanges = /**
  218. * Do a change detection run to make sure there were no changes.
  219. */
  220. function () { this.changeDetectorRef.checkNoChanges(); };
  221. /**
  222. * Set whether the fixture should autodetect changes.
  223. *
  224. * Also runs detectChanges once so that any existing change is detected.
  225. */
  226. /**
  227. * Set whether the fixture should autodetect changes.
  228. *
  229. * Also runs detectChanges once so that any existing change is detected.
  230. */
  231. ComponentFixture.prototype.autoDetectChanges = /**
  232. * Set whether the fixture should autodetect changes.
  233. *
  234. * Also runs detectChanges once so that any existing change is detected.
  235. */
  236. function (autoDetect) {
  237. if (autoDetect === void 0) { autoDetect = true; }
  238. if (this.ngZone == null) {
  239. throw new Error('Cannot call autoDetectChanges when ComponentFixtureNoNgZone is set');
  240. }
  241. this._autoDetect = autoDetect;
  242. this.detectChanges();
  243. };
  244. /**
  245. * Return whether the fixture is currently stable or has async tasks that have not been completed
  246. * yet.
  247. */
  248. /**
  249. * Return whether the fixture is currently stable or has async tasks that have not been completed
  250. * yet.
  251. */
  252. ComponentFixture.prototype.isStable = /**
  253. * Return whether the fixture is currently stable or has async tasks that have not been completed
  254. * yet.
  255. */
  256. function () { return this._isStable && !this.ngZone.hasPendingMacrotasks; };
  257. /**
  258. * Get a promise that resolves when the fixture is stable.
  259. *
  260. * This can be used to resume testing after events have triggered asynchronous activity or
  261. * asynchronous change detection.
  262. */
  263. /**
  264. * Get a promise that resolves when the fixture is stable.
  265. *
  266. * This can be used to resume testing after events have triggered asynchronous activity or
  267. * asynchronous change detection.
  268. */
  269. ComponentFixture.prototype.whenStable = /**
  270. * Get a promise that resolves when the fixture is stable.
  271. *
  272. * This can be used to resume testing after events have triggered asynchronous activity or
  273. * asynchronous change detection.
  274. */
  275. function () {
  276. var _this = this;
  277. if (this.isStable()) {
  278. return Promise.resolve(false);
  279. }
  280. else if (this._promise !== null) {
  281. return this._promise;
  282. }
  283. else {
  284. this._promise = new Promise(function (res) { _this._resolve = res; });
  285. return this._promise;
  286. }
  287. };
  288. ComponentFixture.prototype._getRenderer = function () {
  289. if (this._renderer === undefined) {
  290. this._renderer = this.componentRef.injector.get(RendererFactory2, null);
  291. }
  292. return this._renderer;
  293. };
  294. /**
  295. * Get a promise that resolves when the ui state is stable following animations.
  296. */
  297. /**
  298. * Get a promise that resolves when the ui state is stable following animations.
  299. */
  300. ComponentFixture.prototype.whenRenderingDone = /**
  301. * Get a promise that resolves when the ui state is stable following animations.
  302. */
  303. function () {
  304. var renderer = this._getRenderer();
  305. if (renderer && renderer.whenRenderingDone) {
  306. return renderer.whenRenderingDone();
  307. }
  308. return this.whenStable();
  309. };
  310. /**
  311. * Trigger component destruction.
  312. */
  313. /**
  314. * Trigger component destruction.
  315. */
  316. ComponentFixture.prototype.destroy = /**
  317. * Trigger component destruction.
  318. */
  319. function () {
  320. if (!this._isDestroyed) {
  321. this.componentRef.destroy();
  322. if (this._onUnstableSubscription != null) {
  323. this._onUnstableSubscription.unsubscribe();
  324. this._onUnstableSubscription = null;
  325. }
  326. if (this._onStableSubscription != null) {
  327. this._onStableSubscription.unsubscribe();
  328. this._onStableSubscription = null;
  329. }
  330. if (this._onMicrotaskEmptySubscription != null) {
  331. this._onMicrotaskEmptySubscription.unsubscribe();
  332. this._onMicrotaskEmptySubscription = null;
  333. }
  334. if (this._onErrorSubscription != null) {
  335. this._onErrorSubscription.unsubscribe();
  336. this._onErrorSubscription = null;
  337. }
  338. this._isDestroyed = true;
  339. }
  340. };
  341. return ComponentFixture;
  342. }());
  343. function scheduleMicroTask(fn) {
  344. Zone.current.scheduleMicroTask('scheduleMicrotask', fn);
  345. }
  346. /**
  347. * @license
  348. * Copyright Google Inc. All Rights Reserved.
  349. *
  350. * Use of this source code is governed by an MIT-style license that can be
  351. * found in the LICENSE file at https://angular.io/license
  352. */
  353. var FakeAsyncTestZoneSpec = Zone['FakeAsyncTestZoneSpec'];
  354. var ProxyZoneSpec = Zone['ProxyZoneSpec'];
  355. var _fakeAsyncTestZoneSpec = null;
  356. /**
  357. * Clears out the shared fake async zone for a test.
  358. * To be called in a global `beforeEach`.
  359. *
  360. * @experimental
  361. */
  362. function resetFakeAsyncZone() {
  363. _fakeAsyncTestZoneSpec = null;
  364. ProxyZoneSpec.assertPresent().resetDelegate();
  365. }
  366. var _inFakeAsyncCall = false;
  367. /**
  368. * Wraps a function to be executed in the fakeAsync zone:
  369. * - microtasks are manually executed by calling `flushMicrotasks()`,
  370. * - timers are synchronous, `tick()` simulates the asynchronous passage of time.
  371. *
  372. * If there are any pending timers at the end of the function, an exception will be thrown.
  373. *
  374. * Can be used to wrap inject() calls.
  375. *
  376. * ## Example
  377. *
  378. * {@example core/testing/ts/fake_async.ts region='basic'}
  379. *
  380. * @param fn
  381. * @returns The function wrapped to be executed in the fakeAsync zone
  382. *
  383. * @experimental
  384. */
  385. function fakeAsync(fn) {
  386. // Not using an arrow function to preserve context passed from call site
  387. return function () {
  388. var args = [];
  389. for (var _i = 0; _i < arguments.length; _i++) {
  390. args[_i] = arguments[_i];
  391. }
  392. var proxyZoneSpec = ProxyZoneSpec.assertPresent();
  393. if (_inFakeAsyncCall) {
  394. throw new Error('fakeAsync() calls can not be nested');
  395. }
  396. _inFakeAsyncCall = true;
  397. try {
  398. if (!_fakeAsyncTestZoneSpec) {
  399. if (proxyZoneSpec.getDelegate() instanceof FakeAsyncTestZoneSpec) {
  400. throw new Error('fakeAsync() calls can not be nested');
  401. }
  402. _fakeAsyncTestZoneSpec = new FakeAsyncTestZoneSpec();
  403. }
  404. var res = void 0;
  405. var lastProxyZoneSpec = proxyZoneSpec.getDelegate();
  406. proxyZoneSpec.setDelegate(_fakeAsyncTestZoneSpec);
  407. try {
  408. res = fn.apply(this, args);
  409. flushMicrotasks();
  410. }
  411. finally {
  412. proxyZoneSpec.setDelegate(lastProxyZoneSpec);
  413. }
  414. if (_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length > 0) {
  415. throw new Error(_fakeAsyncTestZoneSpec.pendingPeriodicTimers.length + " " +
  416. "periodic timer(s) still in the queue.");
  417. }
  418. if (_fakeAsyncTestZoneSpec.pendingTimers.length > 0) {
  419. throw new Error(_fakeAsyncTestZoneSpec.pendingTimers.length + " timer(s) still in the queue.");
  420. }
  421. return res;
  422. }
  423. finally {
  424. _inFakeAsyncCall = false;
  425. resetFakeAsyncZone();
  426. }
  427. };
  428. }
  429. function _getFakeAsyncZoneSpec() {
  430. if (_fakeAsyncTestZoneSpec == null) {
  431. throw new Error('The code should be running in the fakeAsync zone to call this function');
  432. }
  433. return _fakeAsyncTestZoneSpec;
  434. }
  435. /**
  436. * Simulates the asynchronous passage of time for the timers in the fakeAsync zone.
  437. *
  438. * The microtasks queue is drained at the very start of this function and after any timer callback
  439. * has been executed.
  440. *
  441. * ## Example
  442. *
  443. * {@example core/testing/ts/fake_async.ts region='basic'}
  444. *
  445. * @experimental
  446. */
  447. function tick(millis) {
  448. if (millis === void 0) { millis = 0; }
  449. _getFakeAsyncZoneSpec().tick(millis);
  450. }
  451. /**
  452. * Simulates the asynchronous passage of time for the timers in the fakeAsync zone by
  453. * draining the macrotask queue until it is empty. The returned value is the milliseconds
  454. * of time that would have been elapsed.
  455. *
  456. * @param maxTurns
  457. * @returns The simulated time elapsed, in millis.
  458. *
  459. * @experimental
  460. */
  461. function flush(maxTurns) {
  462. return _getFakeAsyncZoneSpec().flush(maxTurns);
  463. }
  464. /**
  465. * Discard all remaining periodic tasks.
  466. *
  467. * @experimental
  468. */
  469. function discardPeriodicTasks() {
  470. var zoneSpec = _getFakeAsyncZoneSpec();
  471. var pendingTimers = zoneSpec.pendingPeriodicTimers;
  472. zoneSpec.pendingPeriodicTimers.length = 0;
  473. }
  474. /**
  475. * Flush any pending microtasks.
  476. *
  477. * @experimental
  478. */
  479. function flushMicrotasks() {
  480. _getFakeAsyncZoneSpec().flushMicrotasks();
  481. }
  482. /**
  483. * @license
  484. * Copyright Google Inc. All Rights Reserved.
  485. *
  486. * Use of this source code is governed by an MIT-style license that can be
  487. * found in the LICENSE file at https://angular.io/license
  488. */
  489. /**
  490. * Injectable completer that allows signaling completion of an asynchronous test. Used internally.
  491. */
  492. var AsyncTestCompleter = /** @class */ (function () {
  493. function AsyncTestCompleter() {
  494. var _this = this;
  495. this._promise = new Promise(function (res, rej) {
  496. _this._resolve = res;
  497. _this._reject = rej;
  498. });
  499. }
  500. AsyncTestCompleter.prototype.done = function (value) { this._resolve(value); };
  501. AsyncTestCompleter.prototype.fail = function (error, stackTrace) { this._reject(error); };
  502. Object.defineProperty(AsyncTestCompleter.prototype, "promise", {
  503. get: function () { return this._promise; },
  504. enumerable: true,
  505. configurable: true
  506. });
  507. return AsyncTestCompleter;
  508. }());
  509. /**
  510. * @license
  511. * Copyright Google Inc. All Rights Reserved.
  512. *
  513. * Use of this source code is governed by an MIT-style license that can be
  514. * found in the LICENSE file at https://angular.io/license
  515. */
  516. function unimplemented() {
  517. throw Error('unimplemented');
  518. }
  519. /**
  520. * Special interface to the compiler only used by testing
  521. *
  522. * @experimental
  523. */
  524. var TestingCompiler = /** @class */ (function (_super) {
  525. __extends(TestingCompiler, _super);
  526. function TestingCompiler() {
  527. return _super !== null && _super.apply(this, arguments) || this;
  528. }
  529. Object.defineProperty(TestingCompiler.prototype, "injector", {
  530. get: function () { throw unimplemented(); },
  531. enumerable: true,
  532. configurable: true
  533. });
  534. TestingCompiler.prototype.overrideModule = function (module, overrides) {
  535. throw unimplemented();
  536. };
  537. TestingCompiler.prototype.overrideDirective = function (directive, overrides) {
  538. throw unimplemented();
  539. };
  540. TestingCompiler.prototype.overrideComponent = function (component, overrides) {
  541. throw unimplemented();
  542. };
  543. TestingCompiler.prototype.overridePipe = function (directive, overrides) {
  544. throw unimplemented();
  545. };
  546. /**
  547. * Allows to pass the compile summary from AOT compilation to the JIT compiler,
  548. * so that it can use the code generated by AOT.
  549. */
  550. /**
  551. * Allows to pass the compile summary from AOT compilation to the JIT compiler,
  552. * so that it can use the code generated by AOT.
  553. */
  554. TestingCompiler.prototype.loadAotSummaries = /**
  555. * Allows to pass the compile summary from AOT compilation to the JIT compiler,
  556. * so that it can use the code generated by AOT.
  557. */
  558. function (summaries) { throw unimplemented(); };
  559. /**
  560. * Gets the component factory for the given component.
  561. * This assumes that the component has been compiled before calling this call using
  562. * `compileModuleAndAllComponents*`.
  563. */
  564. /**
  565. * Gets the component factory for the given component.
  566. * This assumes that the component has been compiled before calling this call using
  567. * `compileModuleAndAllComponents*`.
  568. */
  569. TestingCompiler.prototype.getComponentFactory = /**
  570. * Gets the component factory for the given component.
  571. * This assumes that the component has been compiled before calling this call using
  572. * `compileModuleAndAllComponents*`.
  573. */
  574. function (component) { throw unimplemented(); };
  575. /**
  576. * Returns the component type that is stored in the given error.
  577. * This can be used for errors created by compileModule...
  578. */
  579. /**
  580. * Returns the component type that is stored in the given error.
  581. * This can be used for errors created by compileModule...
  582. */
  583. TestingCompiler.prototype.getComponentFromError = /**
  584. * Returns the component type that is stored in the given error.
  585. * This can be used for errors created by compileModule...
  586. */
  587. function (error) { throw unimplemented(); };
  588. TestingCompiler.decorators = [
  589. { type: Injectable },
  590. ];
  591. /** @nocollapse */
  592. TestingCompiler.ctorParameters = function () { return []; };
  593. return TestingCompiler;
  594. }(Compiler));
  595. /**
  596. * A factory for creating a Compiler
  597. *
  598. * @experimental
  599. */
  600. var TestingCompilerFactory = /** @class */ (function () {
  601. function TestingCompilerFactory() {
  602. }
  603. return TestingCompilerFactory;
  604. }());
  605. /**
  606. * @license
  607. * Copyright Google Inc. All Rights Reserved.
  608. *
  609. * Use of this source code is governed by an MIT-style license that can be
  610. * found in the LICENSE file at https://angular.io/license
  611. */
  612. var UNDEFINED = new Object();
  613. /**
  614. * An abstract class for inserting the root test component element in a platform independent way.
  615. *
  616. * @experimental
  617. */
  618. var TestComponentRenderer = /** @class */ (function () {
  619. function TestComponentRenderer() {
  620. }
  621. TestComponentRenderer.prototype.insertRootElement = function (rootElementId) { };
  622. return TestComponentRenderer;
  623. }());
  624. var _nextRootElementId = 0;
  625. /**
  626. * @experimental
  627. */
  628. var ComponentFixtureAutoDetect = new InjectionToken('ComponentFixtureAutoDetect');
  629. /**
  630. * @experimental
  631. */
  632. var ComponentFixtureNoNgZone = new InjectionToken('ComponentFixtureNoNgZone');
  633. /**
  634. * @whatItDoes Configures and initializes environment for unit testing and provides methods for
  635. * creating components and services in unit tests.
  636. * @description
  637. *
  638. * TestBed is the primary api for writing unit tests for Angular applications and libraries.
  639. *
  640. * @stable
  641. */
  642. var TestBed = /** @class */ (function () {
  643. function TestBed() {
  644. this._instantiated = false;
  645. this._compiler = null;
  646. this._moduleRef = null;
  647. this._moduleFactory = null;
  648. this._compilerOptions = [];
  649. this._moduleOverrides = [];
  650. this._componentOverrides = [];
  651. this._directiveOverrides = [];
  652. this._pipeOverrides = [];
  653. this._providers = [];
  654. this._declarations = [];
  655. this._imports = [];
  656. this._schemas = [];
  657. this._activeFixtures = [];
  658. this._testEnvAotSummaries = function () { return []; };
  659. this._aotSummaries = [];
  660. this._templateOverrides = [];
  661. this.platform = null;
  662. this.ngModule = null;
  663. }
  664. /**
  665. * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
  666. * angular module. These are common to every test in the suite.
  667. *
  668. * This may only be called once, to set up the common providers for the current test
  669. * suite on the current platform. If you absolutely need to change the providers,
  670. * first use `resetTestEnvironment`.
  671. *
  672. * Test modules and platforms for individual platforms are available from
  673. * '@angular/<platform_name>/testing'.
  674. *
  675. * @experimental
  676. */
  677. /**
  678. * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
  679. * angular module. These are common to every test in the suite.
  680. *
  681. * This may only be called once, to set up the common providers for the current test
  682. * suite on the current platform. If you absolutely need to change the providers,
  683. * first use `resetTestEnvironment`.
  684. *
  685. * Test modules and platforms for individual platforms are available from
  686. * '@angular/<platform_name>/testing'.
  687. *
  688. * @experimental
  689. */
  690. TestBed.initTestEnvironment = /**
  691. * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
  692. * angular module. These are common to every test in the suite.
  693. *
  694. * This may only be called once, to set up the common providers for the current test
  695. * suite on the current platform. If you absolutely need to change the providers,
  696. * first use `resetTestEnvironment`.
  697. *
  698. * Test modules and platforms for individual platforms are available from
  699. * '@angular/<platform_name>/testing'.
  700. *
  701. * @experimental
  702. */
  703. function (ngModule, platform, aotSummaries) {
  704. var testBed = getTestBed();
  705. testBed.initTestEnvironment(ngModule, platform, aotSummaries);
  706. return testBed;
  707. };
  708. /**
  709. * Reset the providers for the test injector.
  710. *
  711. * @experimental
  712. */
  713. /**
  714. * Reset the providers for the test injector.
  715. *
  716. * @experimental
  717. */
  718. TestBed.resetTestEnvironment = /**
  719. * Reset the providers for the test injector.
  720. *
  721. * @experimental
  722. */
  723. function () { getTestBed().resetTestEnvironment(); };
  724. TestBed.resetTestingModule = function () {
  725. getTestBed().resetTestingModule();
  726. return TestBed;
  727. };
  728. /**
  729. * Allows overriding default compiler providers and settings
  730. * which are defined in test_injector.js
  731. */
  732. /**
  733. * Allows overriding default compiler providers and settings
  734. * which are defined in test_injector.js
  735. */
  736. TestBed.configureCompiler = /**
  737. * Allows overriding default compiler providers and settings
  738. * which are defined in test_injector.js
  739. */
  740. function (config) {
  741. getTestBed().configureCompiler(config);
  742. return TestBed;
  743. };
  744. /**
  745. * Allows overriding default providers, directives, pipes, modules of the test injector,
  746. * which are defined in test_injector.js
  747. */
  748. /**
  749. * Allows overriding default providers, directives, pipes, modules of the test injector,
  750. * which are defined in test_injector.js
  751. */
  752. TestBed.configureTestingModule = /**
  753. * Allows overriding default providers, directives, pipes, modules of the test injector,
  754. * which are defined in test_injector.js
  755. */
  756. function (moduleDef) {
  757. getTestBed().configureTestingModule(moduleDef);
  758. return TestBed;
  759. };
  760. /**
  761. * Compile components with a `templateUrl` for the test's NgModule.
  762. * It is necessary to call this function
  763. * as fetching urls is asynchronous.
  764. */
  765. /**
  766. * Compile components with a `templateUrl` for the test's NgModule.
  767. * It is necessary to call this function
  768. * as fetching urls is asynchronous.
  769. */
  770. TestBed.compileComponents = /**
  771. * Compile components with a `templateUrl` for the test's NgModule.
  772. * It is necessary to call this function
  773. * as fetching urls is asynchronous.
  774. */
  775. function () { return getTestBed().compileComponents(); };
  776. TestBed.overrideModule = function (ngModule, override) {
  777. getTestBed().overrideModule(ngModule, override);
  778. return TestBed;
  779. };
  780. TestBed.overrideComponent = function (component, override) {
  781. getTestBed().overrideComponent(component, override);
  782. return TestBed;
  783. };
  784. TestBed.overrideDirective = function (directive, override) {
  785. getTestBed().overrideDirective(directive, override);
  786. return TestBed;
  787. };
  788. TestBed.overridePipe = function (pipe, override) {
  789. getTestBed().overridePipe(pipe, override);
  790. return TestBed;
  791. };
  792. TestBed.overrideTemplate = function (component, template) {
  793. getTestBed().overrideComponent(component, { set: { template: template, templateUrl: (null) } });
  794. return TestBed;
  795. };
  796. /**
  797. * Overrides the template of the given component, compiling the template
  798. * in the context of the TestingModule.
  799. *
  800. * Note: This works for JIT and AOTed components as well.
  801. */
  802. /**
  803. * Overrides the template of the given component, compiling the template
  804. * in the context of the TestingModule.
  805. *
  806. * Note: This works for JIT and AOTed components as well.
  807. */
  808. TestBed.overrideTemplateUsingTestingModule = /**
  809. * Overrides the template of the given component, compiling the template
  810. * in the context of the TestingModule.
  811. *
  812. * Note: This works for JIT and AOTed components as well.
  813. */
  814. function (component, template) {
  815. getTestBed().overrideTemplateUsingTestingModule(component, template);
  816. return TestBed;
  817. };
  818. TestBed.overrideProvider = function (token, provider) {
  819. getTestBed().overrideProvider(token, provider);
  820. return TestBed;
  821. };
  822. TestBed.deprecatedOverrideProvider = function (token, provider) {
  823. getTestBed().deprecatedOverrideProvider(token, provider);
  824. return TestBed;
  825. };
  826. TestBed.get = function (token, notFoundValue) {
  827. if (notFoundValue === void 0) { notFoundValue = Injector.THROW_IF_NOT_FOUND; }
  828. return getTestBed().get(token, notFoundValue);
  829. };
  830. TestBed.createComponent = function (component) {
  831. return getTestBed().createComponent(component);
  832. };
  833. /**
  834. * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
  835. * angular module. These are common to every test in the suite.
  836. *
  837. * This may only be called once, to set up the common providers for the current test
  838. * suite on the current platform. If you absolutely need to change the providers,
  839. * first use `resetTestEnvironment`.
  840. *
  841. * Test modules and platforms for individual platforms are available from
  842. * '@angular/<platform_name>/testing'.
  843. *
  844. * @experimental
  845. */
  846. /**
  847. * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
  848. * angular module. These are common to every test in the suite.
  849. *
  850. * This may only be called once, to set up the common providers for the current test
  851. * suite on the current platform. If you absolutely need to change the providers,
  852. * first use `resetTestEnvironment`.
  853. *
  854. * Test modules and platforms for individual platforms are available from
  855. * '@angular/<platform_name>/testing'.
  856. *
  857. * @experimental
  858. */
  859. TestBed.prototype.initTestEnvironment = /**
  860. * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
  861. * angular module. These are common to every test in the suite.
  862. *
  863. * This may only be called once, to set up the common providers for the current test
  864. * suite on the current platform. If you absolutely need to change the providers,
  865. * first use `resetTestEnvironment`.
  866. *
  867. * Test modules and platforms for individual platforms are available from
  868. * '@angular/<platform_name>/testing'.
  869. *
  870. * @experimental
  871. */
  872. function (ngModule, platform, aotSummaries) {
  873. if (this.platform || this.ngModule) {
  874. throw new Error('Cannot set base providers because it has already been called');
  875. }
  876. this.platform = platform;
  877. this.ngModule = ngModule;
  878. if (aotSummaries) {
  879. this._testEnvAotSummaries = aotSummaries;
  880. }
  881. };
  882. /**
  883. * Reset the providers for the test injector.
  884. *
  885. * @experimental
  886. */
  887. /**
  888. * Reset the providers for the test injector.
  889. *
  890. * @experimental
  891. */
  892. TestBed.prototype.resetTestEnvironment = /**
  893. * Reset the providers for the test injector.
  894. *
  895. * @experimental
  896. */
  897. function () {
  898. this.resetTestingModule();
  899. this.platform = (null);
  900. this.ngModule = (null);
  901. this._testEnvAotSummaries = function () { return []; };
  902. };
  903. TestBed.prototype.resetTestingModule = function () {
  904. ɵclearOverrides();
  905. this._aotSummaries = [];
  906. this._templateOverrides = [];
  907. this._compiler = (null);
  908. this._moduleOverrides = [];
  909. this._componentOverrides = [];
  910. this._directiveOverrides = [];
  911. this._pipeOverrides = [];
  912. this._moduleRef = (null);
  913. this._moduleFactory = (null);
  914. this._compilerOptions = [];
  915. this._providers = [];
  916. this._declarations = [];
  917. this._imports = [];
  918. this._schemas = [];
  919. this._instantiated = false;
  920. this._activeFixtures.forEach(function (fixture) {
  921. try {
  922. fixture.destroy();
  923. }
  924. catch (e) {
  925. console.error('Error during cleanup of component', {
  926. component: fixture.componentInstance,
  927. stacktrace: e,
  928. });
  929. }
  930. });
  931. this._activeFixtures = [];
  932. };
  933. TestBed.prototype.configureCompiler = function (config) {
  934. this._assertNotInstantiated('TestBed.configureCompiler', 'configure the compiler');
  935. this._compilerOptions.push(config);
  936. };
  937. TestBed.prototype.configureTestingModule = function (moduleDef) {
  938. this._assertNotInstantiated('TestBed.configureTestingModule', 'configure the test module');
  939. if (moduleDef.providers) {
  940. (_a = this._providers).push.apply(_a, moduleDef.providers);
  941. }
  942. if (moduleDef.declarations) {
  943. (_b = this._declarations).push.apply(_b, moduleDef.declarations);
  944. }
  945. if (moduleDef.imports) {
  946. (_c = this._imports).push.apply(_c, moduleDef.imports);
  947. }
  948. if (moduleDef.schemas) {
  949. (_d = this._schemas).push.apply(_d, moduleDef.schemas);
  950. }
  951. if (moduleDef.aotSummaries) {
  952. this._aotSummaries.push(moduleDef.aotSummaries);
  953. }
  954. var _a, _b, _c, _d;
  955. };
  956. TestBed.prototype.compileComponents = function () {
  957. var _this = this;
  958. if (this._moduleFactory || this._instantiated) {
  959. return Promise.resolve(null);
  960. }
  961. var moduleType = this._createCompilerAndModule();
  962. return this._compiler.compileModuleAndAllComponentsAsync(moduleType)
  963. .then(function (moduleAndComponentFactories) {
  964. _this._moduleFactory = moduleAndComponentFactories.ngModuleFactory;
  965. });
  966. };
  967. TestBed.prototype._initIfNeeded = function () {
  968. if (this._instantiated) {
  969. return;
  970. }
  971. if (!this._moduleFactory) {
  972. try {
  973. var moduleType = this._createCompilerAndModule();
  974. this._moduleFactory =
  975. this._compiler.compileModuleAndAllComponentsSync(moduleType).ngModuleFactory;
  976. }
  977. catch (e) {
  978. var errorCompType = this._compiler.getComponentFromError(e);
  979. if (errorCompType) {
  980. throw new Error("This test module uses the component " + ɵstringify(errorCompType) + " which is using a \"templateUrl\" or \"styleUrls\", but they were never compiled. " +
  981. "Please call \"TestBed.compileComponents\" before your test.");
  982. }
  983. else {
  984. throw e;
  985. }
  986. }
  987. }
  988. for (var _i = 0, _a = this._templateOverrides; _i < _a.length; _i++) {
  989. var _b = _a[_i], component = _b.component, templateOf = _b.templateOf;
  990. var compFactory = this._compiler.getComponentFactory(templateOf);
  991. ɵoverrideComponentView(component, compFactory);
  992. }
  993. var ngZone = new NgZone({ enableLongStackTrace: true });
  994. var providers = [{ provide: NgZone, useValue: ngZone }];
  995. var ngZoneInjector = Injector.create({
  996. providers: providers,
  997. parent: this.platform.injector,
  998. name: this._moduleFactory.moduleType.name
  999. });
  1000. this._moduleRef = this._moduleFactory.create(ngZoneInjector);
  1001. // ApplicationInitStatus.runInitializers() is marked @internal to core. So casting to any
  1002. // before accessing it.
  1003. // ApplicationInitStatus.runInitializers() is marked @internal to core. So casting to any
  1004. // before accessing it.
  1005. this._moduleRef.injector.get(ApplicationInitStatus).runInitializers();
  1006. this._instantiated = true;
  1007. };
  1008. TestBed.prototype._createCompilerAndModule = function () {
  1009. var _this = this;
  1010. var providers = this._providers.concat([{ provide: TestBed, useValue: this }]);
  1011. var declarations = this._declarations.concat(this._templateOverrides.map(function (entry) { return entry.templateOf; }));
  1012. var imports = [this.ngModule, this._imports];
  1013. var schemas = this._schemas;
  1014. var DynamicTestModule = /** @class */ (function () {
  1015. function DynamicTestModule() {
  1016. }
  1017. DynamicTestModule.decorators = [
  1018. { type: NgModule, args: [{ providers: providers, declarations: declarations, imports: imports, schemas: schemas },] },
  1019. ];
  1020. /** @nocollapse */
  1021. DynamicTestModule.ctorParameters = function () { return []; };
  1022. return DynamicTestModule;
  1023. }());
  1024. var compilerFactory = this.platform.injector.get(TestingCompilerFactory);
  1025. this._compiler = compilerFactory.createTestingCompiler(this._compilerOptions);
  1026. for (var _i = 0, _a = [this._testEnvAotSummaries].concat(this._aotSummaries); _i < _a.length; _i++) {
  1027. var summary = _a[_i];
  1028. this._compiler.loadAotSummaries(summary);
  1029. }
  1030. this._moduleOverrides.forEach(function (entry) { return _this._compiler.overrideModule(entry[0], entry[1]); });
  1031. this._componentOverrides.forEach(function (entry) { return _this._compiler.overrideComponent(entry[0], entry[1]); });
  1032. this._directiveOverrides.forEach(function (entry) { return _this._compiler.overrideDirective(entry[0], entry[1]); });
  1033. this._pipeOverrides.forEach(function (entry) { return _this._compiler.overridePipe(entry[0], entry[1]); });
  1034. return DynamicTestModule;
  1035. };
  1036. TestBed.prototype._assertNotInstantiated = function (methodName, methodDescription) {
  1037. if (this._instantiated) {
  1038. throw new Error("Cannot " + methodDescription + " when the test module has already been instantiated. " +
  1039. ("Make sure you are not using `inject` before `" + methodName + "`."));
  1040. }
  1041. };
  1042. TestBed.prototype.get = function (token, notFoundValue) {
  1043. if (notFoundValue === void 0) { notFoundValue = Injector.THROW_IF_NOT_FOUND; }
  1044. this._initIfNeeded();
  1045. if (token === TestBed) {
  1046. return this;
  1047. }
  1048. // Tests can inject things from the ng module and from the compiler,
  1049. // but the ng module can't inject things from the compiler and vice versa.
  1050. var result = this._moduleRef.injector.get(token, UNDEFINED);
  1051. return result === UNDEFINED ? this._compiler.injector.get(token, notFoundValue) : result;
  1052. };
  1053. TestBed.prototype.execute = function (tokens, fn, context) {
  1054. var _this = this;
  1055. this._initIfNeeded();
  1056. var params = tokens.map(function (t) { return _this.get(t); });
  1057. return fn.apply(context, params);
  1058. };
  1059. TestBed.prototype.overrideModule = function (ngModule, override) {
  1060. this._assertNotInstantiated('overrideModule', 'override module metadata');
  1061. this._moduleOverrides.push([ngModule, override]);
  1062. };
  1063. TestBed.prototype.overrideComponent = function (component, override) {
  1064. this._assertNotInstantiated('overrideComponent', 'override component metadata');
  1065. this._componentOverrides.push([component, override]);
  1066. };
  1067. TestBed.prototype.overrideDirective = function (directive, override) {
  1068. this._assertNotInstantiated('overrideDirective', 'override directive metadata');
  1069. this._directiveOverrides.push([directive, override]);
  1070. };
  1071. TestBed.prototype.overridePipe = function (pipe, override) {
  1072. this._assertNotInstantiated('overridePipe', 'override pipe metadata');
  1073. this._pipeOverrides.push([pipe, override]);
  1074. };
  1075. TestBed.prototype.overrideProvider = function (token, provider) {
  1076. this.overrideProviderImpl(token, provider);
  1077. };
  1078. TestBed.prototype.deprecatedOverrideProvider = function (token, provider) {
  1079. this.overrideProviderImpl(token, provider, /* deprecated */ /* deprecated */ true);
  1080. };
  1081. TestBed.prototype.overrideProviderImpl = function (token, provider, deprecated) {
  1082. if (deprecated === void 0) { deprecated = false; }
  1083. var flags = 0;
  1084. var value;
  1085. if (provider.useFactory) {
  1086. flags |= 1024 /* TypeFactoryProvider */;
  1087. value = provider.useFactory;
  1088. }
  1089. else {
  1090. flags |= 256 /* TypeValueProvider */;
  1091. value = provider.useValue;
  1092. }
  1093. var deps = (provider.deps || []).map(function (dep) {
  1094. var depFlags = 0;
  1095. var depToken;
  1096. if (Array.isArray(dep)) {
  1097. dep.forEach(function (entry) {
  1098. if (entry instanceof Optional) {
  1099. depFlags |= 2 /* Optional */;
  1100. }
  1101. else if (entry instanceof SkipSelf) {
  1102. depFlags |= 1 /* SkipSelf */;
  1103. }
  1104. else {
  1105. depToken = entry;
  1106. }
  1107. });
  1108. }
  1109. else {
  1110. depToken = dep;
  1111. }
  1112. return [depFlags, depToken];
  1113. });
  1114. ɵoverrideProvider({ token: token, flags: flags, deps: deps, value: value, deprecatedBehavior: deprecated });
  1115. };
  1116. TestBed.prototype.overrideTemplateUsingTestingModule = function (component, template) {
  1117. this._assertNotInstantiated('overrideTemplateUsingTestingModule', 'override template');
  1118. var OverrideComponent = /** @class */ (function () {
  1119. function OverrideComponent() {
  1120. }
  1121. OverrideComponent.decorators = [
  1122. { type: Component, args: [{ selector: 'empty', template: template },] },
  1123. ];
  1124. /** @nocollapse */
  1125. OverrideComponent.ctorParameters = function () { return []; };
  1126. return OverrideComponent;
  1127. }());
  1128. this._templateOverrides.push({ component: component, templateOf: OverrideComponent });
  1129. };
  1130. TestBed.prototype.createComponent = function (component) {
  1131. var _this = this;
  1132. this._initIfNeeded();
  1133. var componentFactory = this._compiler.getComponentFactory(component);
  1134. if (!componentFactory) {
  1135. throw new Error("Cannot create the component " + ɵstringify(component) + " as it was not imported into the testing module!");
  1136. }
  1137. var noNgZone = this.get(ComponentFixtureNoNgZone, false);
  1138. var autoDetect = this.get(ComponentFixtureAutoDetect, false);
  1139. var ngZone = noNgZone ? null : this.get(NgZone, null);
  1140. var testComponentRenderer = this.get(TestComponentRenderer);
  1141. var rootElId = "root" + _nextRootElementId++;
  1142. testComponentRenderer.insertRootElement(rootElId);
  1143. var initComponent = function () {
  1144. var componentRef = componentFactory.create(Injector.NULL, [], "#" + rootElId, _this._moduleRef);
  1145. return new ComponentFixture(componentRef, ngZone, autoDetect);
  1146. };
  1147. var fixture = !ngZone ? initComponent() : ngZone.run(initComponent);
  1148. this._activeFixtures.push(fixture);
  1149. return fixture;
  1150. };
  1151. return TestBed;
  1152. }());
  1153. var _testBed = (null);
  1154. /**
  1155. * @experimental
  1156. */
  1157. function getTestBed() {
  1158. return _testBed = _testBed || new TestBed();
  1159. }
  1160. /**
  1161. * Allows injecting dependencies in `beforeEach()` and `it()`.
  1162. *
  1163. * Example:
  1164. *
  1165. * ```
  1166. * beforeEach(inject([Dependency, AClass], (dep, object) => {
  1167. * // some code that uses `dep` and `object`
  1168. * // ...
  1169. * }));
  1170. *
  1171. * it('...', inject([AClass], (object) => {
  1172. * object.doSomething();
  1173. * expect(...);
  1174. * })
  1175. * ```
  1176. *
  1177. * Notes:
  1178. * - inject is currently a function because of some Traceur limitation the syntax should
  1179. * eventually
  1180. * becomes `it('...', @Inject (object: AClass, async: AsyncTestCompleter) => { ... });`
  1181. *
  1182. * @stable
  1183. */
  1184. function inject(tokens, fn) {
  1185. var testBed = getTestBed();
  1186. if (tokens.indexOf(AsyncTestCompleter) >= 0) {
  1187. // Not using an arrow function to preserve context passed from call site
  1188. return function () {
  1189. var _this = this;
  1190. // Return an async test method that returns a Promise if AsyncTestCompleter is one of
  1191. // the injected tokens.
  1192. return testBed.compileComponents().then(function () {
  1193. var completer = testBed.get(AsyncTestCompleter);
  1194. testBed.execute(tokens, fn, _this);
  1195. return completer.promise;
  1196. });
  1197. };
  1198. }
  1199. else {
  1200. // Not using an arrow function to preserve context passed from call site
  1201. return function () { return testBed.execute(tokens, fn, this); };
  1202. }
  1203. }
  1204. /**
  1205. * @experimental
  1206. */
  1207. var InjectSetupWrapper = /** @class */ (function () {
  1208. function InjectSetupWrapper(_moduleDef) {
  1209. this._moduleDef = _moduleDef;
  1210. }
  1211. InjectSetupWrapper.prototype._addModule = function () {
  1212. var moduleDef = this._moduleDef();
  1213. if (moduleDef) {
  1214. getTestBed().configureTestingModule(moduleDef);
  1215. }
  1216. };
  1217. InjectSetupWrapper.prototype.inject = function (tokens, fn) {
  1218. var self = this;
  1219. // Not using an arrow function to preserve context passed from call site
  1220. return function () {
  1221. self._addModule();
  1222. return inject(tokens, fn).call(this);
  1223. };
  1224. };
  1225. return InjectSetupWrapper;
  1226. }());
  1227. function withModule(moduleDef, fn) {
  1228. if (fn) {
  1229. // Not using an arrow function to preserve context passed from call site
  1230. return function () {
  1231. var testBed = getTestBed();
  1232. if (moduleDef) {
  1233. testBed.configureTestingModule(moduleDef);
  1234. }
  1235. return fn.apply(this);
  1236. };
  1237. }
  1238. return new InjectSetupWrapper(function () { return moduleDef; });
  1239. }
  1240. /**
  1241. * @license
  1242. * Copyright Google Inc. All Rights Reserved.
  1243. *
  1244. * Use of this source code is governed by an MIT-style license that can be
  1245. * found in the LICENSE file at https://angular.io/license
  1246. */
  1247. var _global$1 = (typeof window === 'undefined' ? global : window);
  1248. // Reset the test providers and the fake async zone before each test.
  1249. if (_global$1.beforeEach) {
  1250. _global$1.beforeEach(function () {
  1251. TestBed.resetTestingModule();
  1252. resetFakeAsyncZone();
  1253. });
  1254. }
  1255. // TODO(juliemr): remove this, only used because we need to export something to have compilation
  1256. // work.
  1257. var __core_private_testing_placeholder__ = '';
  1258. /**
  1259. * @license
  1260. * Copyright Google Inc. All Rights Reserved.
  1261. *
  1262. * Use of this source code is governed by an MIT-style license that can be
  1263. * found in the LICENSE file at https://angular.io/license
  1264. */
  1265. /**
  1266. * @license
  1267. * Copyright Google Inc. All Rights Reserved.
  1268. *
  1269. * Use of this source code is governed by an MIT-style license that can be
  1270. * found in the LICENSE file at https://angular.io/license
  1271. */
  1272. /**
  1273. * @license
  1274. * Copyright Google Inc. All Rights Reserved.
  1275. *
  1276. * Use of this source code is governed by an MIT-style license that can be
  1277. * found in the LICENSE file at https://angular.io/license
  1278. */
  1279. // This file only reexports content of the `src` folder. Keep it that way.
  1280. /**
  1281. * Generated bundle index. Do not edit.
  1282. */
  1283. export { async, ComponentFixture, resetFakeAsyncZone, fakeAsync, tick, flush, discardPeriodicTasks, flushMicrotasks, TestComponentRenderer, ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestBed, getTestBed, inject, InjectSetupWrapper, withModule, __core_private_testing_placeholder__, TestingCompiler as ɵTestingCompiler, TestingCompilerFactory as ɵTestingCompilerFactory };
  1284. //# sourceMappingURL=testing.js.map