@angular/core 14.1.0 → 14.2.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/esm2020/src/application_ref.mjs +26 -21
  2. package/esm2020/src/core_private_export.mjs +2 -2
  3. package/esm2020/src/core_render3_private_export.mjs +4 -4
  4. package/esm2020/src/di/injector_compatibility.mjs +2 -2
  5. package/esm2020/src/di/interface/defs.mjs +4 -1
  6. package/esm2020/src/render3/component_ref.mjs +4 -31
  7. package/esm2020/src/render3/definition.mjs +5 -5
  8. package/esm2020/src/render3/index.mjs +4 -4
  9. package/esm2020/src/render3/instructions/change_detection.mjs +3 -19
  10. package/esm2020/src/render3/instructions/element_validation.mjs +9 -5
  11. package/esm2020/src/render3/instructions/shared.mjs +10 -50
  12. package/esm2020/src/render3/interfaces/view.mjs +1 -1
  13. package/esm2020/src/render3/jit/module.mjs +2 -6
  14. package/esm2020/src/render3/util/change_detection_utils.mjs +7 -3
  15. package/esm2020/src/render3/util/misc_utils.mjs +1 -7
  16. package/esm2020/src/version.mjs +1 -1
  17. package/esm2020/testing/src/logger.mjs +3 -3
  18. package/esm2020/testing/src/ng_zone_mock.mjs +3 -3
  19. package/esm2020/testing/src/test_bed.mjs +442 -15
  20. package/esm2020/testing/src/test_bed_common.mjs +1 -1
  21. package/esm2020/testing/src/test_bed_compiler.mjs +823 -0
  22. package/esm2020/testing/src/test_hooks.mjs +5 -5
  23. package/esm2020/testing/src/testing.mjs +1 -1
  24. package/fesm2015/core.mjs +56 -132
  25. package/fesm2015/core.mjs.map +1 -1
  26. package/fesm2015/testing.mjs +132 -218
  27. package/fesm2015/testing.mjs.map +1 -1
  28. package/fesm2020/core.mjs +56 -132
  29. package/fesm2020/core.mjs.map +1 -1
  30. package/fesm2020/testing.mjs +132 -219
  31. package/fesm2020/testing.mjs.map +1 -1
  32. package/index.d.ts +7 -100
  33. package/package.json +1 -1
  34. package/testing/index.d.ts +18 -94
  35. package/esm2020/src/render3/interfaces/player.mjs +0 -9
  36. package/esm2020/testing/src/r3_test_bed.mjs +0 -433
  37. package/esm2020/testing/src/r3_test_bed_compiler.mjs +0 -823
@@ -1,10 +1,10 @@
1
1
  /**
2
- * @license Angular v14.1.0
2
+ * @license Angular v14.2.0-next.1
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
6
6
 
7
- import { getDebugNode as getDebugNode$1, RendererFactory2 as RendererFactory2$1, ɵstringify, ɵReflectionCapabilities, Directive, Component, Pipe, NgModule, ɵgetInjectableDef, resolveForwardRef as resolveForwardRef$1, ɵNG_COMP_DEF, ɵRender3NgModuleRef, ApplicationInitStatus, LOCALE_ID as LOCALE_ID$1, ɵDEFAULT_LOCALE_ID, ɵsetLocaleId, ɵRender3ComponentFactory, ɵcompileComponent, ɵNG_DIR_DEF, ɵcompileDirective, ɵNG_PIPE_DEF, ɵcompilePipe, ɵNG_MOD_DEF, ɵtransitiveScopesFor, ɵpatchComponentDefWithScope, ɵNG_INJ_DEF, ɵcompileNgModuleDefs, NgZone, Compiler, COMPILER_OPTIONS, ɵNgModuleFactory, ModuleWithComponentFactories, InjectionToken as InjectionToken$1, Injector as Injector$1, InjectFlags as InjectFlags$1, ɵsetAllowDuplicateNgModuleIdsForTest, ɵresetCompiledComponents, ɵsetUnknownElementStrictMode as ɵsetUnknownElementStrictMode$1, ɵsetUnknownPropertyStrictMode as ɵsetUnknownPropertyStrictMode$1, ɵgetUnknownElementStrictMode as ɵgetUnknownElementStrictMode$1, ɵgetUnknownPropertyStrictMode as ɵgetUnknownPropertyStrictMode$1, ɵflushModuleScopingQueueAsMuchAsPossible } from '@angular/core';
7
+ import { getDebugNode as getDebugNode$1, RendererFactory2 as RendererFactory2$1, InjectionToken as InjectionToken$1, ɵstringify, ɵReflectionCapabilities, Directive, Component, Pipe, NgModule, ɵgetInjectableDef, resolveForwardRef as resolveForwardRef$1, ɵNG_COMP_DEF, ɵRender3NgModuleRef, ApplicationInitStatus, LOCALE_ID as LOCALE_ID$1, ɵDEFAULT_LOCALE_ID, ɵsetLocaleId, ɵRender3ComponentFactory, ɵcompileComponent, ɵNG_DIR_DEF, ɵcompileDirective, ɵNG_PIPE_DEF, ɵcompilePipe, ɵNG_MOD_DEF, ɵtransitiveScopesFor, ɵpatchComponentDefWithScope, ɵNG_INJ_DEF, ɵcompileNgModuleDefs, NgZone, Compiler, COMPILER_OPTIONS, ɵNgModuleFactory, ModuleWithComponentFactories, Injector as Injector$1, InjectFlags as InjectFlags$1, ɵsetAllowDuplicateNgModuleIdsForTest, ɵresetCompiledComponents, ɵsetUnknownElementStrictMode as ɵsetUnknownElementStrictMode$1, ɵsetUnknownPropertyStrictMode as ɵsetUnknownPropertyStrictMode$1, ɵgetUnknownElementStrictMode as ɵgetUnknownElementStrictMode$1, ɵgetUnknownPropertyStrictMode as ɵgetUnknownPropertyStrictMode$1, ɵflushModuleScopingQueueAsMuchAsPossible } from '@angular/core';
8
8
  import { ResourceLoader } from '@angular/compiler';
9
9
  import { Subject, Subscription } from 'rxjs';
10
10
 
@@ -413,6 +413,37 @@ function flushMicrotasks() {
413
413
  throw new Error(fakeAsyncTestModuleNotLoadedErrorMessage);
414
414
  }
415
415
 
416
+ /**
417
+ * @license
418
+ * Copyright Google LLC All Rights Reserved.
419
+ *
420
+ * Use of this source code is governed by an MIT-style license that can be
421
+ * found in the LICENSE file at https://angular.io/license
422
+ */
423
+ /** Whether test modules should be torn down by default. */
424
+ const TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT = true;
425
+ /** Whether unknown elements in templates should throw by default. */
426
+ const THROW_ON_UNKNOWN_ELEMENTS_DEFAULT = false;
427
+ /** Whether unknown properties in templates should throw by default. */
428
+ const THROW_ON_UNKNOWN_PROPERTIES_DEFAULT = false;
429
+ /**
430
+ * An abstract class for inserting the root test component element in a platform independent way.
431
+ *
432
+ * @publicApi
433
+ */
434
+ class TestComponentRenderer {
435
+ insertRootElement(rootElementId) { }
436
+ removeAllRootElements() { }
437
+ }
438
+ /**
439
+ * @publicApi
440
+ */
441
+ const ComponentFixtureAutoDetect = new InjectionToken$1('ComponentFixtureAutoDetect');
442
+ /**
443
+ * @publicApi
444
+ */
445
+ const ComponentFixtureNoNgZone = new InjectionToken$1('ComponentFixtureNoNgZone');
446
+
416
447
  /**
417
448
  * @license
418
449
  * Copyright Google LLC All Rights Reserved.
@@ -803,6 +834,9 @@ function ɵɵdefineInjector(options) {
803
834
  function getInjectableDef(type) {
804
835
  return getOwnDefinition(type, NG_PROV_DEF) || getOwnDefinition(type, NG_INJECTABLE_DEF);
805
836
  }
837
+ function isInjectable(type) {
838
+ return getInjectableDef(type) !== null;
839
+ }
806
840
  /**
807
841
  * Return definition only if it is defined directly on `type` and is not inherited from a base
808
842
  * class of `type`.
@@ -2047,7 +2081,7 @@ function setCurrentInjector(injector) {
2047
2081
  function injectInjectorOnly(token, flags = InjectFlags.Default) {
2048
2082
  if (_currentInjector === undefined) {
2049
2083
  throw new RuntimeError(-203 /* RuntimeErrorCode.MISSING_INJECTION_CONTEXT */, ngDevMode &&
2050
- `inject() must be called from an injection context (a constructor, a factory function or a field initializer)`);
2084
+ `inject() must be called from an injection context such as a constructor, a factory function, a field initializer, or a function used with \`EnvironmentInjector#runInContext\`.`);
2051
2085
  }
2052
2086
  else if (_currentInjector === null) {
2053
2087
  return injectRootLimpMode(token, undefined, flags);
@@ -2573,7 +2607,6 @@ function extractDirectiveDef(type) {
2573
2607
  function nonNull(value) {
2574
2608
  return value !== null;
2575
2609
  }
2576
- const autoRegisterModuleById = {};
2577
2610
  /**
2578
2611
  * @codeGenApi
2579
2612
  */
@@ -2589,9 +2622,6 @@ function ɵɵdefineNgModule(def) {
2589
2622
  schemas: def.schemas || null,
2590
2623
  id: def.id || null,
2591
2624
  };
2592
- if (def.id != null) {
2593
- autoRegisterModuleById[def.id] = def.type;
2594
- }
2595
2625
  return res;
2596
2626
  });
2597
2627
  }
@@ -2745,6 +2775,10 @@ function getDirectiveDef(type) {
2745
2775
  function getPipeDef$1(type) {
2746
2776
  return type[NG_PIPE_DEF] || null;
2747
2777
  }
2778
+ function isStandalone(type) {
2779
+ const def = getComponentDef$1(type) || getDirectiveDef(type) || getPipeDef$1(type);
2780
+ return def !== null ? def.standalone : false;
2781
+ }
2748
2782
  function getNgModuleDef(type, throwNotFound) {
2749
2783
  const ngModuleDef = type[NG_MOD_DEF] || null;
2750
2784
  if (!ngModuleDef && throwNotFound === true) {
@@ -5477,11 +5511,6 @@ function setAllowDuplicateNgModuleIdsForTest(allowDuplicates) {
5477
5511
  * Use of this source code is governed by an MIT-style license that can be
5478
5512
  * found in the LICENSE file at https://angular.io/license
5479
5513
  */
5480
- const defaultScheduler = (() => (typeof requestAnimationFrame !== 'undefined' &&
5481
- requestAnimationFrame || // browser only
5482
- setTimeout // everything else
5483
- )
5484
- .bind(_global$1))();
5485
5514
  /**
5486
5515
  *
5487
5516
  * @codeGenApi
@@ -7618,7 +7647,7 @@ class Version {
7618
7647
  /**
7619
7648
  * @publicApi
7620
7649
  */
7621
- const VERSION = new Version('14.1.0');
7650
+ const VERSION = new Version('14.2.0-next.1');
7622
7651
 
7623
7652
  /**
7624
7653
  * @license
@@ -7834,9 +7863,10 @@ function handleUnknownPropertyError(propName, tagName, nodeType, lView) {
7834
7863
  'a part of an @NgModule where this component is declared';
7835
7864
  if (KNOWN_CONTROL_FLOW_DIRECTIVES.has(propName)) {
7836
7865
  // Most likely this is a control flow directive (such as `*ngIf`) used in
7837
- // a template, but the `CommonModule` is not imported.
7866
+ // a template, but the directive or the `CommonModule` is not imported.
7867
+ const correspondingImport = KNOWN_CONTROL_FLOW_DIRECTIVES.get(propName);
7838
7868
  message += `\nIf the '${propName}' is an Angular control flow directive, ` +
7839
- `please make sure that the 'CommonModule' is ${importLocation}.`;
7869
+ `please make sure that either the '${correspondingImport}' directive or the 'CommonModule' is ${importLocation}.`;
7840
7870
  }
7841
7871
  else {
7842
7872
  // May be an Angular component, which is not imported/declared?
@@ -7915,11 +7945,14 @@ function getTemplateLocationDetails(lView) {
7915
7945
  return componentClassName ? ` (used in the '${componentClassName}' component template)` : '';
7916
7946
  }
7917
7947
  /**
7918
- * The set of known control flow directives.
7948
+ * The set of known control flow directives and their corresponding imports.
7919
7949
  * We use this set to produce a more precises error message with a note
7920
7950
  * that the `CommonModule` should also be included.
7921
7951
  */
7922
- const KNOWN_CONTROL_FLOW_DIRECTIVES = new Set(['ngIf', 'ngFor', 'ngSwitch', 'ngSwitchCase', 'ngSwitchDefault']);
7952
+ const KNOWN_CONTROL_FLOW_DIRECTIVES = new Map([
7953
+ ['ngIf', 'NgIf'], ['ngFor', 'NgForOf'], ['ngSwitchCase', 'NgSwitchCase'],
7954
+ ['ngSwitchDefault', 'NgSwitchDefault']
7955
+ ]);
7923
7956
  /**
7924
7957
  * Returns true if the tag name is allowed by specified schemas.
7925
7958
  * @param schemas Array of schemas
@@ -12010,11 +12043,6 @@ class LContainerDebug {
12010
12043
  * Use of this source code is governed by an MIT-style license that can be
12011
12044
  * found in the LICENSE file at https://angular.io/license
12012
12045
  */
12013
- /**
12014
- * A permanent marker promise which signifies that the current CD tree is
12015
- * clean.
12016
- */
12017
- const _CLEAN_PROMISE = (() => Promise.resolve(null))();
12018
12046
  /**
12019
12047
  * Invoke `HostBindingsFunction`s for view.
12020
12048
  *
@@ -13395,13 +13423,15 @@ function refreshContainsDirtyView(lView) {
13395
13423
  for (let lContainer = getFirstLContainer(lView); lContainer !== null; lContainer = getNextLContainer(lContainer)) {
13396
13424
  for (let i = CONTAINER_HEADER_OFFSET; i < lContainer.length; i++) {
13397
13425
  const embeddedLView = lContainer[i];
13398
- if (embeddedLView[FLAGS] & 512 /* LViewFlags.RefreshTransplantedView */) {
13399
- const embeddedTView = embeddedLView[TVIEW];
13400
- ngDevMode && assertDefined(embeddedTView, 'TView must be allocated');
13401
- refreshView(embeddedTView, embeddedLView, embeddedTView.template, embeddedLView[CONTEXT]);
13402
- }
13403
- else if (embeddedLView[TRANSPLANTED_VIEWS_TO_REFRESH] > 0) {
13404
- refreshContainsDirtyView(embeddedLView);
13426
+ if (viewAttachedToChangeDetector(embeddedLView)) {
13427
+ if (embeddedLView[FLAGS] & 512 /* LViewFlags.RefreshTransplantedView */) {
13428
+ const embeddedTView = embeddedLView[TVIEW];
13429
+ ngDevMode && assertDefined(embeddedTView, 'TView must be allocated');
13430
+ refreshView(embeddedTView, embeddedLView, embeddedTView.template, embeddedLView[CONTEXT]);
13431
+ }
13432
+ else if (embeddedLView[TRANSPLANTED_VIEWS_TO_REFRESH] > 0) {
13433
+ refreshContainsDirtyView(embeddedLView);
13434
+ }
13405
13435
  }
13406
13436
  }
13407
13437
  }
@@ -13510,42 +13540,6 @@ function markViewDirty(lView) {
13510
13540
  }
13511
13541
  return null;
13512
13542
  }
13513
- /**
13514
- * Used to schedule change detection on the whole application.
13515
- *
13516
- * Unlike `tick`, `scheduleTick` coalesces multiple calls into one change detection run.
13517
- * It is usually called indirectly by calling `markDirty` when the view needs to be
13518
- * re-rendered.
13519
- *
13520
- * Typically `scheduleTick` uses `requestAnimationFrame` to coalesce multiple
13521
- * `scheduleTick` requests. The scheduling function can be overridden in
13522
- * `renderComponent`'s `scheduler` option.
13523
- */
13524
- function scheduleTick(rootContext, flags) {
13525
- const nothingScheduled = rootContext.flags === 0 /* RootContextFlags.Empty */;
13526
- if (nothingScheduled && rootContext.clean == _CLEAN_PROMISE) {
13527
- // https://github.com/angular/angular/issues/39296
13528
- // should only attach the flags when really scheduling a tick
13529
- rootContext.flags |= flags;
13530
- let res;
13531
- rootContext.clean = new Promise((r) => res = r);
13532
- rootContext.scheduler(() => {
13533
- if (rootContext.flags & 1 /* RootContextFlags.DetectChanges */) {
13534
- rootContext.flags &= ~1 /* RootContextFlags.DetectChanges */;
13535
- tickRootContext(rootContext);
13536
- }
13537
- if (rootContext.flags & 2 /* RootContextFlags.FlushPlayers */) {
13538
- rootContext.flags &= ~2 /* RootContextFlags.FlushPlayers */;
13539
- const playerHandler = rootContext.playerHandler;
13540
- if (playerHandler) {
13541
- playerHandler.flushPlayers();
13542
- }
13543
- }
13544
- rootContext.clean = _CLEAN_PROMISE;
13545
- res(null);
13546
- });
13547
- }
13548
- }
13549
13543
  function tickRootContext(rootContext) {
13550
13544
  for (let i = 0; i < rootContext.components.length; i++) {
13551
13545
  const rootComponent = rootContext.components[i];
@@ -13654,7 +13648,6 @@ function storePropertyBindingMetadata(tData, tNode, propertyName, bindingIndex,
13654
13648
  }
13655
13649
  }
13656
13650
  }
13657
- const CLEAN_PROMISE = _CLEAN_PROMISE;
13658
13651
  function getOrCreateLViewCleanup(view) {
13659
13652
  // top level variables should not be exported for performance reasons (PERF_NOTES.md)
13660
13653
  return view[CLEANUP] || (view[CLEANUP] = ngDevMode ? new LCleanup() : []);
@@ -14413,14 +14406,8 @@ function createRootComponent(componentView, componentDef, rootLView, rootContext
14413
14406
  }
14414
14407
  return component;
14415
14408
  }
14416
- function createRootContext(scheduler, playerHandler) {
14417
- return {
14418
- components: [],
14419
- scheduler: scheduler || defaultScheduler,
14420
- clean: CLEAN_PROMISE,
14421
- playerHandler: playerHandler || null,
14422
- flags: 0 /* RootContextFlags.Empty */
14423
- };
14409
+ function createRootContext() {
14410
+ return { components: [] };
14424
14411
  }
14425
14412
  /**
14426
14413
  * Used to enable lifecycle hooks on the root component.
@@ -14440,25 +14427,6 @@ function LifecycleHooksFeature() {
14440
14427
  ngDevMode && assertDefined(tNode, 'TNode is required');
14441
14428
  registerPostOrderHooks(getLView()[TVIEW], tNode);
14442
14429
  }
14443
- /**
14444
- * Wait on component until it is rendered.
14445
- *
14446
- * This function returns a `Promise` which is resolved when the component's
14447
- * change detection is executed. This is determined by finding the scheduler
14448
- * associated with the `component`'s render tree and waiting until the scheduler
14449
- * flushes. If nothing is scheduled, the function returns a resolved promise.
14450
- *
14451
- * Example:
14452
- * ```
14453
- * await whenRendered(myComponent);
14454
- * ```
14455
- *
14456
- * @param component Component to wait upon
14457
- * @returns Promise which resolves when the component is rendered.
14458
- */
14459
- function whenRendered(component) {
14460
- return getRootContext(component).clean;
14461
- }
14462
14430
 
14463
14431
  /**
14464
14432
  * @license
@@ -15443,21 +15411,6 @@ function detectChanges(component) {
15443
15411
  const view = getComponentViewByInstance(component);
15444
15412
  detectChangesInternal(view[TVIEW], view, component);
15445
15413
  }
15446
- /**
15447
- * Marks the component as dirty (needing change detection). Marking a component dirty will
15448
- * schedule a change detection on it at some point in the future.
15449
- *
15450
- * Marking an already dirty component as dirty won't do anything. Only one outstanding change
15451
- * detection can be scheduled per component tree.
15452
- *
15453
- * @param component Component to mark as dirty.
15454
- */
15455
- function markDirty(component) {
15456
- ngDevMode && assertDefined(component, 'component');
15457
- const rootView = markViewDirty(getComponentViewByInstance(component));
15458
- ngDevMode && assertDefined(rootView[CONTEXT], 'rootContext should be defined');
15459
- scheduleTick(rootView[CONTEXT], 1 /* RootContextFlags.DetectChanges */);
15460
- }
15461
15414
 
15462
15415
  /**
15463
15416
  * @license
@@ -24619,10 +24572,6 @@ function compileNgModuleDefs(moduleType, ngModule, allowDuplicateDeclarationsInR
24619
24572
  configurable: !!ngDevMode,
24620
24573
  });
24621
24574
  }
24622
- function isStandalone(type) {
24623
- const def = getComponentDef$1(type) || getDirectiveDef(type) || getPipeDef$1(type);
24624
- return def !== null ? def.standalone : false;
24625
- }
24626
24575
  function generateStandaloneInDeclarationsError(type, location) {
24627
24576
  const prefix = `Unexpected "${stringifyForError(type)}" found in the "declarations" array of the`;
24628
24577
  const suffix = `"${stringifyForError(type)}" is marked as standalone and can't be declared ` +
@@ -25233,7 +25182,7 @@ function assertNoStandaloneComponents(types, resolver, location) {
25233
25182
  }
25234
25183
  });
25235
25184
  }
25236
- class R3TestBedCompiler {
25185
+ class TestBedCompiler {
25237
25186
  constructor(platform, additionalModuleTypes) {
25238
25187
  this.platform = platform;
25239
25188
  this.additionalModuleTypes = additionalModuleTypes;
@@ -26034,49 +25983,23 @@ class R3TestCompiler {
26034
25983
  * Use of this source code is governed by an MIT-style license that can be
26035
25984
  * found in the LICENSE file at https://angular.io/license
26036
25985
  */
26037
- /** Whether test modules should be torn down by default. */
26038
- const TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT = true;
26039
- /** Whether unknown elements in templates should throw by default. */
26040
- const THROW_ON_UNKNOWN_ELEMENTS_DEFAULT = false;
26041
- /** Whether unknown properties in templates should throw by default. */
26042
- const THROW_ON_UNKNOWN_PROPERTIES_DEFAULT = false;
25986
+ let _nextRootElementId = 0;
26043
25987
  /**
26044
- * An abstract class for inserting the root test component element in a platform independent way.
25988
+ * Returns a singleton of the `TestBed` class.
26045
25989
  *
26046
25990
  * @publicApi
26047
25991
  */
26048
- class TestComponentRenderer {
26049
- insertRootElement(rootElementId) { }
26050
- removeAllRootElements() { }
25992
+ function getTestBed() {
25993
+ return TestBedImpl.INSTANCE;
26051
25994
  }
26052
- /**
26053
- * @publicApi
26054
- */
26055
- const ComponentFixtureAutoDetect = new InjectionToken$1('ComponentFixtureAutoDetect');
26056
- /**
26057
- * @publicApi
26058
- */
26059
- const ComponentFixtureNoNgZone = new InjectionToken$1('ComponentFixtureNoNgZone');
26060
-
26061
- /**
26062
- * @license
26063
- * Copyright Google LLC All Rights Reserved.
26064
- *
26065
- * Use of this source code is governed by an MIT-style license that can be
26066
- * found in the LICENSE file at https://angular.io/license
26067
- */
26068
- let _nextRootElementId = 0;
26069
25995
  /**
26070
25996
  * @description
26071
25997
  * Configures and initializes environment for unit testing and provides methods for
26072
25998
  * creating components and services in unit tests.
26073
25999
  *
26074
26000
  * TestBed is the primary api for writing unit tests for Angular applications and libraries.
26075
- *
26076
- * Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
26077
- * according to the compiler used.
26078
26001
  */
26079
- class TestBedRender3 {
26002
+ class TestBedImpl {
26080
26003
  constructor() {
26081
26004
  // Properties
26082
26005
  this.platform = null;
@@ -26084,7 +26007,15 @@ class TestBedRender3 {
26084
26007
  this._compiler = null;
26085
26008
  this._testModuleRef = null;
26086
26009
  this._activeFixtures = [];
26087
- this._globalCompilationChecked = false;
26010
+ /**
26011
+ * Internal-only flag to indicate whether a module
26012
+ * scoping queue has been checked and flushed already.
26013
+ * @nodoc
26014
+ */
26015
+ this.globalCompilationChecked = false;
26016
+ }
26017
+ static get INSTANCE() {
26018
+ return TestBedImpl._INSTANCE = TestBedImpl._INSTANCE || new TestBedImpl();
26088
26019
  }
26089
26020
  /**
26090
26021
  * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
@@ -26100,7 +26031,7 @@ class TestBedRender3 {
26100
26031
  * @publicApi
26101
26032
  */
26102
26033
  static initTestEnvironment(ngModule, platform, options) {
26103
- const testBed = _getTestBedRender3();
26034
+ const testBed = TestBedImpl.INSTANCE;
26104
26035
  testBed.initTestEnvironment(ngModule, platform, options);
26105
26036
  return testBed;
26106
26037
  }
@@ -26110,19 +26041,17 @@ class TestBedRender3 {
26110
26041
  * @publicApi
26111
26042
  */
26112
26043
  static resetTestEnvironment() {
26113
- _getTestBedRender3().resetTestEnvironment();
26044
+ TestBedImpl.INSTANCE.resetTestEnvironment();
26114
26045
  }
26115
26046
  static configureCompiler(config) {
26116
- _getTestBedRender3().configureCompiler(config);
26117
- return TestBedRender3;
26047
+ return TestBedImpl.INSTANCE.configureCompiler(config);
26118
26048
  }
26119
26049
  /**
26120
26050
  * Allows overriding default providers, directives, pipes, modules of the test injector,
26121
26051
  * which are defined in test_injector.js
26122
26052
  */
26123
26053
  static configureTestingModule(moduleDef) {
26124
- _getTestBedRender3().configureTestingModule(moduleDef);
26125
- return TestBedRender3;
26054
+ return TestBedImpl.INSTANCE.configureTestingModule(moduleDef);
26126
26055
  }
26127
26056
  /**
26128
26057
  * Compile components with a `templateUrl` for the test's NgModule.
@@ -26130,27 +26059,22 @@ class TestBedRender3 {
26130
26059
  * as fetching urls is asynchronous.
26131
26060
  */
26132
26061
  static compileComponents() {
26133
- return _getTestBedRender3().compileComponents();
26062
+ return TestBedImpl.INSTANCE.compileComponents();
26134
26063
  }
26135
26064
  static overrideModule(ngModule, override) {
26136
- _getTestBedRender3().overrideModule(ngModule, override);
26137
- return TestBedRender3;
26065
+ return TestBedImpl.INSTANCE.overrideModule(ngModule, override);
26138
26066
  }
26139
26067
  static overrideComponent(component, override) {
26140
- _getTestBedRender3().overrideComponent(component, override);
26141
- return TestBedRender3;
26068
+ return TestBedImpl.INSTANCE.overrideComponent(component, override);
26142
26069
  }
26143
26070
  static overrideDirective(directive, override) {
26144
- _getTestBedRender3().overrideDirective(directive, override);
26145
- return TestBedRender3;
26071
+ return TestBedImpl.INSTANCE.overrideDirective(directive, override);
26146
26072
  }
26147
26073
  static overridePipe(pipe, override) {
26148
- _getTestBedRender3().overridePipe(pipe, override);
26149
- return TestBedRender3;
26074
+ return TestBedImpl.INSTANCE.overridePipe(pipe, override);
26150
26075
  }
26151
26076
  static overrideTemplate(component, template) {
26152
- _getTestBedRender3().overrideComponent(component, { set: { template, templateUrl: null } });
26153
- return TestBedRender3;
26077
+ return TestBedImpl.INSTANCE.overrideTemplate(component, template);
26154
26078
  }
26155
26079
  /**
26156
26080
  * Overrides the template of the given component, compiling the template
@@ -26159,32 +26083,32 @@ class TestBedRender3 {
26159
26083
  * Note: This works for JIT and AOTed components as well.
26160
26084
  */
26161
26085
  static overrideTemplateUsingTestingModule(component, template) {
26162
- _getTestBedRender3().overrideTemplateUsingTestingModule(component, template);
26163
- return TestBedRender3;
26086
+ return TestBedImpl.INSTANCE.overrideTemplateUsingTestingModule(component, template);
26164
26087
  }
26165
26088
  static overrideProvider(token, provider) {
26166
- _getTestBedRender3().overrideProvider(token, provider);
26167
- return TestBedRender3;
26089
+ return TestBedImpl.INSTANCE.overrideProvider(token, provider);
26168
26090
  }
26169
26091
  static inject(token, notFoundValue, flags) {
26170
- return _getTestBedRender3().inject(token, notFoundValue, flags);
26092
+ return TestBedImpl.INSTANCE.inject(token, notFoundValue, flags);
26171
26093
  }
26172
26094
  /** @deprecated from v9.0.0 use TestBed.inject */
26173
26095
  static get(token, notFoundValue = Injector$1.THROW_IF_NOT_FOUND, flags = InjectFlags$1.Default) {
26174
- return _getTestBedRender3().inject(token, notFoundValue, flags);
26096
+ return TestBedImpl.INSTANCE.inject(token, notFoundValue, flags);
26175
26097
  }
26176
26098
  static createComponent(component) {
26177
- return _getTestBedRender3().createComponent(component);
26099
+ return TestBedImpl.INSTANCE.createComponent(component);
26178
26100
  }
26179
26101
  static resetTestingModule() {
26180
- _getTestBedRender3().resetTestingModule();
26181
- return TestBedRender3;
26102
+ return TestBedImpl.INSTANCE.resetTestingModule();
26182
26103
  }
26183
- static shouldTearDownTestingModule() {
26184
- return _getTestBedRender3().shouldTearDownTestingModule();
26104
+ static execute(tokens, fn, context) {
26105
+ return TestBedImpl.INSTANCE.execute(tokens, fn, context);
26185
26106
  }
26186
- static tearDownTestingModule() {
26187
- _getTestBedRender3().tearDownTestingModule();
26107
+ static get platform() {
26108
+ return TestBedImpl.INSTANCE.platform;
26109
+ }
26110
+ static get ngModule() {
26111
+ return TestBedImpl.INSTANCE.ngModule;
26188
26112
  }
26189
26113
  /**
26190
26114
  * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
@@ -26203,12 +26127,12 @@ class TestBedRender3 {
26203
26127
  if (this.platform || this.ngModule) {
26204
26128
  throw new Error('Cannot set base providers because it has already been called');
26205
26129
  }
26206
- TestBedRender3._environmentTeardownOptions = options?.teardown;
26207
- TestBedRender3._environmentErrorOnUnknownElementsOption = options?.errorOnUnknownElements;
26208
- TestBedRender3._environmentErrorOnUnknownPropertiesOption = options?.errorOnUnknownProperties;
26130
+ TestBedImpl._environmentTeardownOptions = options?.teardown;
26131
+ TestBedImpl._environmentErrorOnUnknownElementsOption = options?.errorOnUnknownElements;
26132
+ TestBedImpl._environmentErrorOnUnknownPropertiesOption = options?.errorOnUnknownProperties;
26209
26133
  this.platform = platform;
26210
26134
  this.ngModule = ngModule;
26211
- this._compiler = new R3TestBedCompiler(this.platform, this.ngModule);
26135
+ this._compiler = new TestBedCompiler(this.platform, this.ngModule);
26212
26136
  // TestBed does not have an API which can reliably detect the start of a test, and thus could be
26213
26137
  // used to track the state of the NgModule registry and reset it correctly. Instead, when we
26214
26138
  // know we're in a testing scenario, we disable the check for duplicate NgModule registration
@@ -26225,7 +26149,7 @@ class TestBedRender3 {
26225
26149
  this._compiler = null;
26226
26150
  this.platform = null;
26227
26151
  this.ngModule = null;
26228
- TestBedRender3._environmentTeardownOptions = undefined;
26152
+ TestBedImpl._environmentTeardownOptions = undefined;
26229
26153
  ɵsetAllowDuplicateNgModuleIdsForTest(false);
26230
26154
  }
26231
26155
  resetTestingModule() {
@@ -26234,7 +26158,7 @@ class TestBedRender3 {
26234
26158
  if (this._compiler !== null) {
26235
26159
  this.compiler.restoreOriginalState();
26236
26160
  }
26237
- this._compiler = new R3TestBedCompiler(this.platform, this.ngModule);
26161
+ this._compiler = new TestBedCompiler(this.platform, this.ngModule);
26238
26162
  // Restore the previous value of the "error on unknown elements" option
26239
26163
  ɵsetUnknownElementStrictMode$1(this._previousErrorOnUnknownElementsOption ?? THROW_ON_UNKNOWN_ELEMENTS_DEFAULT);
26240
26164
  // Restore the previous value of the "error on unknown properties" option
@@ -26258,6 +26182,7 @@ class TestBedRender3 {
26258
26182
  this._instanceErrorOnUnknownPropertiesOption = undefined;
26259
26183
  }
26260
26184
  }
26185
+ return this;
26261
26186
  }
26262
26187
  configureCompiler(config) {
26263
26188
  if (config.useJit != null) {
@@ -26266,6 +26191,7 @@ class TestBedRender3 {
26266
26191
  if (config.providers !== undefined) {
26267
26192
  this.compiler.setCompilerProviders(config.providers);
26268
26193
  }
26194
+ return this;
26269
26195
  }
26270
26196
  configureTestingModule(moduleDef) {
26271
26197
  this.assertNotInstantiated('R3TestBed.configureTestingModule', 'configure the test module');
@@ -26286,12 +26212,13 @@ class TestBedRender3 {
26286
26212
  this._previousErrorOnUnknownPropertiesOption = ɵgetUnknownPropertyStrictMode$1();
26287
26213
  ɵsetUnknownPropertyStrictMode$1(this.shouldThrowErrorOnUnknownProperties());
26288
26214
  this.compiler.configureTestingModule(moduleDef);
26215
+ return this;
26289
26216
  }
26290
26217
  compileComponents() {
26291
26218
  return this.compiler.compileComponents();
26292
26219
  }
26293
26220
  inject(token, notFoundValue, flags) {
26294
- if (token === TestBedRender3) {
26221
+ if (token === TestBed) {
26295
26222
  return this;
26296
26223
  }
26297
26224
  const UNDEFINED = {};
@@ -26310,22 +26237,27 @@ class TestBedRender3 {
26310
26237
  overrideModule(ngModule, override) {
26311
26238
  this.assertNotInstantiated('overrideModule', 'override module metadata');
26312
26239
  this.compiler.overrideModule(ngModule, override);
26240
+ return this;
26313
26241
  }
26314
26242
  overrideComponent(component, override) {
26315
26243
  this.assertNotInstantiated('overrideComponent', 'override component metadata');
26316
26244
  this.compiler.overrideComponent(component, override);
26245
+ return this;
26317
26246
  }
26318
26247
  overrideTemplateUsingTestingModule(component, template) {
26319
26248
  this.assertNotInstantiated('R3TestBed.overrideTemplateUsingTestingModule', 'Cannot override template when the test module has already been instantiated');
26320
26249
  this.compiler.overrideTemplateUsingTestingModule(component, template);
26250
+ return this;
26321
26251
  }
26322
26252
  overrideDirective(directive, override) {
26323
26253
  this.assertNotInstantiated('overrideDirective', 'override directive metadata');
26324
26254
  this.compiler.overrideDirective(directive, override);
26255
+ return this;
26325
26256
  }
26326
26257
  overridePipe(pipe, override) {
26327
26258
  this.assertNotInstantiated('overridePipe', 'override pipe metadata');
26328
26259
  this.compiler.overridePipe(pipe, override);
26260
+ return this;
26329
26261
  }
26330
26262
  /**
26331
26263
  * Overwrites all providers for the given token with the given provider definition.
@@ -26333,6 +26265,10 @@ class TestBedRender3 {
26333
26265
  overrideProvider(token, provider) {
26334
26266
  this.assertNotInstantiated('overrideProvider', 'override provider');
26335
26267
  this.compiler.overrideProvider(token, provider);
26268
+ return this;
26269
+ }
26270
+ overrideTemplate(component, template) {
26271
+ return this.overrideComponent(component, { set: { template, templateUrl: null } });
26336
26272
  }
26337
26273
  createComponent(type) {
26338
26274
  const testComponentRenderer = this.inject(TestComponentRenderer);
@@ -26397,10 +26333,10 @@ class TestBedRender3 {
26397
26333
  checkGlobalCompilationFinished() {
26398
26334
  // Checking _testNgModuleRef is null should not be necessary, but is left in as an additional
26399
26335
  // guard that compilations queued in tests (after instantiation) are never flushed accidentally.
26400
- if (!this._globalCompilationChecked && this._testModuleRef === null) {
26336
+ if (!this.globalCompilationChecked && this._testModuleRef === null) {
26401
26337
  ɵflushModuleScopingQueueAsMuchAsPossible();
26402
26338
  }
26403
- this._globalCompilationChecked = true;
26339
+ this.globalCompilationChecked = true;
26404
26340
  }
26405
26341
  destroyActiveFixtures() {
26406
26342
  let errorCount = 0;
@@ -26424,7 +26360,7 @@ class TestBedRender3 {
26424
26360
  }
26425
26361
  shouldRethrowTeardownErrors() {
26426
26362
  const instanceOptions = this._instanceTeardownOptions;
26427
- const environmentOptions = TestBedRender3._environmentTeardownOptions;
26363
+ const environmentOptions = TestBedImpl._environmentTeardownOptions;
26428
26364
  // If the new teardown behavior hasn't been configured, preserve the old behavior.
26429
26365
  if (!instanceOptions && !environmentOptions) {
26430
26366
  return TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT;
@@ -26436,18 +26372,17 @@ class TestBedRender3 {
26436
26372
  shouldThrowErrorOnUnknownElements() {
26437
26373
  // Check if a configuration has been provided to throw when an unknown element is found
26438
26374
  return this._instanceErrorOnUnknownElementsOption ??
26439
- TestBedRender3._environmentErrorOnUnknownElementsOption ??
26440
- THROW_ON_UNKNOWN_ELEMENTS_DEFAULT;
26375
+ TestBedImpl._environmentErrorOnUnknownElementsOption ?? THROW_ON_UNKNOWN_ELEMENTS_DEFAULT;
26441
26376
  }
26442
26377
  shouldThrowErrorOnUnknownProperties() {
26443
26378
  // Check if a configuration has been provided to throw when an unknown property is found
26444
26379
  return this._instanceErrorOnUnknownPropertiesOption ??
26445
- TestBedRender3._environmentErrorOnUnknownPropertiesOption ??
26380
+ TestBedImpl._environmentErrorOnUnknownPropertiesOption ??
26446
26381
  THROW_ON_UNKNOWN_PROPERTIES_DEFAULT;
26447
26382
  }
26448
26383
  shouldTearDownTestingModule() {
26449
26384
  return this._instanceTeardownOptions?.destroyAfterEach ??
26450
- TestBedRender3._environmentTeardownOptions?.destroyAfterEach ??
26385
+ TestBedImpl._environmentTeardownOptions?.destroyAfterEach ??
26451
26386
  TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT;
26452
26387
  }
26453
26388
  tearDownTestingModule() {
@@ -26477,18 +26412,7 @@ class TestBedRender3 {
26477
26412
  }
26478
26413
  }
26479
26414
  }
26480
- let testBed;
26481
- function _getTestBedRender3() {
26482
- return testBed = testBed || new TestBedRender3();
26483
- }
26484
-
26485
- /**
26486
- * @license
26487
- * Copyright Google LLC All Rights Reserved.
26488
- *
26489
- * Use of this source code is governed by an MIT-style license that can be
26490
- * found in the LICENSE file at https://angular.io/license
26491
- */
26415
+ TestBedImpl._INSTANCE = null;
26492
26416
  /**
26493
26417
  * @description
26494
26418
  * Configures and initializes environment for unit testing and provides methods for
@@ -26496,20 +26420,9 @@ function _getTestBedRender3() {
26496
26420
  *
26497
26421
  * `TestBed` is the primary api for writing unit tests for Angular applications and libraries.
26498
26422
  *
26499
- * Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
26500
- * according to the compiler used.
26501
- *
26502
- * @publicApi
26503
- */
26504
- const TestBed = TestBedRender3;
26505
- /**
26506
- * Returns a singleton of the applicable `TestBed`.
26507
- *
26508
- * It will be either an instance of `TestBedViewEngine` or `TestBedRender3`.
26509
- *
26510
26423
  * @publicApi
26511
26424
  */
26512
- const getTestBed = _getTestBedRender3;
26425
+ const TestBed = TestBedImpl;
26513
26426
  /**
26514
26427
  * Allows injecting dependencies in `beforeEach()` and `it()`. Note: this function
26515
26428
  * (imported from the `@angular/core/testing` package) can **only** be used to inject dependencies
@@ -26533,7 +26446,7 @@ const getTestBed = _getTestBedRender3;
26533
26446
  * @publicApi
26534
26447
  */
26535
26448
  function inject(tokens, fn) {
26536
- const testBed = getTestBed();
26449
+ const testBed = TestBedImpl.INSTANCE;
26537
26450
  // Not using an arrow function to preserve context passed from call site
26538
26451
  return function () {
26539
26452
  return testBed.execute(tokens, fn, this);
@@ -26549,7 +26462,7 @@ class InjectSetupWrapper {
26549
26462
  _addModule() {
26550
26463
  const moduleDef = this._moduleDef();
26551
26464
  if (moduleDef) {
26552
- getTestBed().configureTestingModule(moduleDef);
26465
+ TestBedImpl.configureTestingModule(moduleDef);
26553
26466
  }
26554
26467
  }
26555
26468
  inject(tokens, fn) {
@@ -26565,7 +26478,7 @@ function withModule(moduleDef, fn) {
26565
26478
  if (fn) {
26566
26479
  // Not using an arrow function to preserve context passed from call site
26567
26480
  return function () {
26568
- const testBed = getTestBed();
26481
+ const testBed = TestBedImpl.INSTANCE;
26569
26482
  if (moduleDef) {
26570
26483
  testBed.configureTestingModule(moduleDef);
26571
26484
  }
@@ -26595,9 +26508,9 @@ if (_global.afterEach) {
26595
26508
  }
26596
26509
  function getCleanupHook(expectedTeardownValue) {
26597
26510
  return () => {
26598
- // TODO(alxhub): find a better type here
26599
- if (TestBed.shouldTearDownTestingModule() === expectedTeardownValue) {
26600
- TestBed.resetTestingModule();
26511
+ const testBed = TestBedImpl.INSTANCE;
26512
+ if (testBed.shouldTearDownTestingModule() === expectedTeardownValue) {
26513
+ testBed.resetTestingModule();
26601
26514
  resetFakeAsyncZone();
26602
26515
  }
26603
26516
  };