@angular/core 13.1.0-next.1 → 13.1.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 (74) hide show
  1. package/core.d.ts +49 -654
  2. package/esm2020/src/application_module.mjs +2 -4
  3. package/esm2020/src/application_ref.mjs +45 -46
  4. package/esm2020/src/change_detection/change_detector_ref.mjs +9 -6
  5. package/esm2020/src/core.mjs +1 -2
  6. package/esm2020/src/core_private_export.mjs +3 -3
  7. package/esm2020/src/core_render3_private_export.mjs +4 -17
  8. package/esm2020/src/debug/debug_node.mjs +10 -129
  9. package/esm2020/src/di/injectable.mjs +11 -20
  10. package/esm2020/src/di/injector.mjs +6 -268
  11. package/esm2020/src/di/metadata_attr.mjs +2 -9
  12. package/esm2020/src/di/reflective_injector.mjs +3 -1
  13. package/esm2020/src/error_handler.mjs +2 -10
  14. package/esm2020/src/errors.mjs +2 -5
  15. package/esm2020/src/linker/compiler.mjs +33 -50
  16. package/esm2020/src/linker/component_factory_resolver.mjs +1 -38
  17. package/esm2020/src/linker/element_ref.mjs +9 -6
  18. package/esm2020/src/linker/ng_module_factory_loader.mjs +20 -24
  19. package/esm2020/src/linker/template_ref.mjs +4 -6
  20. package/esm2020/src/linker/view_container_ref.mjs +11 -6
  21. package/esm2020/src/metadata/directives.mjs +6 -16
  22. package/esm2020/src/metadata/ng_module.mjs +3 -18
  23. package/esm2020/src/metadata/view.mjs +12 -12
  24. package/esm2020/src/render/api.mjs +2 -6
  25. package/esm2020/src/render3/di_setup.mjs +6 -3
  26. package/esm2020/src/render3/error_code.mjs +1 -1
  27. package/esm2020/src/render3/ng_module_ref.mjs +4 -8
  28. package/esm2020/src/render3/pipe.mjs +11 -3
  29. package/esm2020/src/util/errors.mjs +1 -2
  30. package/esm2020/src/version.mjs +1 -1
  31. package/esm2020/src/view/index.mjs +1 -15
  32. package/esm2020/testing/src/logger.mjs +3 -3
  33. package/esm2020/testing/src/metadata_overrider.mjs +14 -2
  34. package/esm2020/testing/src/ng_zone_mock.mjs +3 -3
  35. package/esm2020/testing/src/test_bed.mjs +3 -526
  36. package/esm2020/testing/src/test_hooks.mjs +3 -3
  37. package/esm2020/testing/src/testing.mjs +1 -2
  38. package/fesm2015/core.mjs +324 -4795
  39. package/fesm2015/core.mjs.map +1 -1
  40. package/fesm2015/testing.mjs +25 -606
  41. package/fesm2015/testing.mjs.map +1 -1
  42. package/fesm2020/core.mjs +322 -4794
  43. package/fesm2020/core.mjs.map +1 -1
  44. package/fesm2020/testing.mjs +24 -607
  45. package/fesm2020/testing.mjs.map +1 -1
  46. package/package.json +1 -1
  47. package/schematics/migrations/entry-components/index.d.ts +11 -0
  48. package/schematics/migrations/entry-components/index.js +71 -0
  49. package/schematics/migrations/entry-components/util.d.ts +16 -0
  50. package/schematics/migrations/entry-components/util.js +57 -0
  51. package/schematics/migrations.json +10 -0
  52. package/schematics/utils/import_manager.js +14 -3
  53. package/schematics/utils/typescript/imports.js +9 -3
  54. package/testing/testing.d.ts +1 -46
  55. package/esm2020/src/codegen_private_exports.mjs +0 -11
  56. package/esm2020/src/debug/proxy.mjs +0 -23
  57. package/esm2020/src/ivy_switch.mjs +0 -11
  58. package/esm2020/src/view/element.mjs +0 -296
  59. package/esm2020/src/view/entrypoint.mjs +0 -63
  60. package/esm2020/src/view/errors.mjs +0 -43
  61. package/esm2020/src/view/ng_content.mjs +0 -47
  62. package/esm2020/src/view/ng_module.mjs +0 -215
  63. package/esm2020/src/view/provider.mjs +0 -490
  64. package/esm2020/src/view/pure_expression.mjs +0 -220
  65. package/esm2020/src/view/query.mjs +0 -180
  66. package/esm2020/src/view/refs.mjs +0 -369
  67. package/esm2020/src/view/services.mjs +0 -751
  68. package/esm2020/src/view/text.mjs +0 -136
  69. package/esm2020/src/view/types.mjs +0 -108
  70. package/esm2020/src/view/util.mjs +0 -369
  71. package/esm2020/src/view/view.mjs +0 -629
  72. package/esm2020/src/view/view_attach.mjs +0 -114
  73. package/esm2020/testing/src/private_export_testing.mjs +0 -9
  74. package/esm2020/testing/src/test_compiler.mjs +0 -69
@@ -1,12 +1,11 @@
1
1
  /**
2
- * @license Angular v13.1.0-next.1
2
+ * @license Angular v13.1.1
3
3
  * (c) 2010-2021 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
6
6
 
7
- import * as i0 from '@angular/core';
8
- import { getDebugNode, RendererFactory2, ɵstringify, ɵReflectionCapabilities, Directive, Component, Pipe, NgModule, ɵgetInjectableDef, resolveForwardRef, ɵNG_COMP_DEF, ɵRender3NgModuleRef, ApplicationInitStatus, LOCALE_ID, ɵ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, Injector, InjectFlags, ɵresetCompiledComponents, ɵflushModuleScopingQueueAsMuchAsPossible, Injectable, ɵclearOverrides, ɵoverrideComponentView, ɵINJECTOR_SCOPE, Optional, SkipSelf, ɵoverrideProvider, ɵivyEnabled } from '@angular/core';
9
- import { __awaiter, __decorate } from 'tslib';
7
+ import { getDebugNode, RendererFactory2, ɵstringify, ɵReflectionCapabilities, Directive, Component, Pipe, NgModule, ɵgetInjectableDef, resolveForwardRef, ɵNG_COMP_DEF, ɵRender3NgModuleRef, ApplicationInitStatus, LOCALE_ID, ɵ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, Injector, InjectFlags, ɵresetCompiledComponents, ɵflushModuleScopingQueueAsMuchAsPossible } from '@angular/core';
8
+ import { __awaiter } from 'tslib';
10
9
  import { ResourceLoader } from '@angular/compiler';
11
10
 
12
11
  /**
@@ -606,8 +605,20 @@ function setMetadata(metadata, set) {
606
605
  }
607
606
  }
608
607
  function _propHashKey(propName, propValue, references) {
608
+ let nextObjectId = 0;
609
+ const objectIds = new Map();
609
610
  const replacer = (key, value) => {
610
- if (typeof value === 'function') {
611
+ if (value !== null && typeof value === 'object') {
612
+ if (objectIds.has(value)) {
613
+ return objectIds.get(value);
614
+ }
615
+ // Record an id for this object such that any later references use the object's id instead
616
+ // of the object itself, in order to break cyclic pointers in objects.
617
+ objectIds.set(value, `ɵobj#${nextObjectId++}`);
618
+ // The first time an object is seen the object itself is serialized.
619
+ return value;
620
+ }
621
+ else if (typeof value === 'function') {
611
622
  value = _serializeReference(value, references);
612
623
  }
613
624
  return value;
@@ -1493,7 +1504,7 @@ const ComponentFixtureNoNgZone = new InjectionToken('ComponentFixtureNoNgZone');
1493
1504
  * Use of this source code is governed by an MIT-style license that can be
1494
1505
  * found in the LICENSE file at https://angular.io/license
1495
1506
  */
1496
- let _nextRootElementId$1 = 0;
1507
+ let _nextRootElementId = 0;
1497
1508
  /**
1498
1509
  * @description
1499
1510
  * Configures and initializes environment for unit testing and provides methods for
@@ -1740,7 +1751,7 @@ class TestBedRender3 {
1740
1751
  }
1741
1752
  createComponent(type) {
1742
1753
  const testComponentRenderer = this.inject(TestComponentRenderer);
1743
- const rootElId = `root${_nextRootElementId$1++}`;
1754
+ const rootElId = `root${_nextRootElementId++}`;
1744
1755
  testComponentRenderer.insertRootElement(rootElId);
1745
1756
  const componentDef = type.ɵcmp;
1746
1757
  if (!componentDef) {
@@ -1869,76 +1880,9 @@ class TestBedRender3 {
1869
1880
  }
1870
1881
  }
1871
1882
  }
1872
- let testBed$1;
1883
+ let testBed;
1873
1884
  function _getTestBedRender3() {
1874
- return testBed$1 = testBed$1 || new TestBedRender3();
1875
- }
1876
-
1877
- /**
1878
- * @license
1879
- * Copyright Google LLC All Rights Reserved.
1880
- *
1881
- * Use of this source code is governed by an MIT-style license that can be
1882
- * found in the LICENSE file at https://angular.io/license
1883
- */
1884
- function unimplemented() {
1885
- throw Error('unimplemented');
1886
- }
1887
- /**
1888
- * Special interface to the compiler only used by testing
1889
- *
1890
- * @publicApi
1891
- */
1892
- class TestingCompiler extends Compiler {
1893
- get injector() {
1894
- throw unimplemented();
1895
- }
1896
- overrideModule(module, overrides) {
1897
- throw unimplemented();
1898
- }
1899
- overrideDirective(directive, overrides) {
1900
- throw unimplemented();
1901
- }
1902
- overrideComponent(component, overrides) {
1903
- throw unimplemented();
1904
- }
1905
- overridePipe(directive, overrides) {
1906
- throw unimplemented();
1907
- }
1908
- /**
1909
- * Allows to pass the compile summary from AOT compilation to the JIT compiler,
1910
- * so that it can use the code generated by AOT.
1911
- */
1912
- loadAotSummaries(summaries) {
1913
- throw unimplemented();
1914
- }
1915
- /**
1916
- * Gets the component factory for the given component.
1917
- * This assumes that the component has been compiled before calling this call using
1918
- * `compileModuleAndAllComponents*`.
1919
- */
1920
- getComponentFactory(component) {
1921
- throw unimplemented();
1922
- }
1923
- /**
1924
- * Returns the component type that is stored in the given error.
1925
- * This can be used for errors created by compileModule...
1926
- */
1927
- getComponentFromError(error) {
1928
- throw unimplemented();
1929
- }
1930
- }
1931
- TestingCompiler.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.0-next.1", ngImport: i0, type: TestingCompiler, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
1932
- TestingCompiler.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.0-next.1", ngImport: i0, type: TestingCompiler });
1933
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.0-next.1", ngImport: i0, type: TestingCompiler, decorators: [{
1934
- type: Injectable
1935
- }] });
1936
- /**
1937
- * A factory for creating a Compiler
1938
- *
1939
- * @publicApi
1940
- */
1941
- class TestingCompilerFactory {
1885
+ return testBed = testBed || new TestBedRender3();
1942
1886
  }
1943
1887
 
1944
1888
  /**
@@ -1948,519 +1892,6 @@ class TestingCompilerFactory {
1948
1892
  * Use of this source code is governed by an MIT-style license that can be
1949
1893
  * found in the LICENSE file at https://angular.io/license
1950
1894
  */
1951
- let _nextRootElementId = 0;
1952
- /**
1953
- * @description
1954
- * Configures and initializes environment for unit testing and provides methods for
1955
- * creating components and services in unit tests.
1956
- *
1957
- * `TestBed` is the primary api for writing unit tests for Angular applications and libraries.
1958
- *
1959
- * Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
1960
- * according to the compiler used.
1961
- */
1962
- class TestBedViewEngine {
1963
- constructor() {
1964
- this._instantiated = false;
1965
- this._compiler = null;
1966
- this._moduleRef = null;
1967
- this._moduleFactory = null;
1968
- this._pendingModuleFactory = null;
1969
- this._compilerOptions = [];
1970
- this._moduleOverrides = [];
1971
- this._componentOverrides = [];
1972
- this._directiveOverrides = [];
1973
- this._pipeOverrides = [];
1974
- this._providers = [];
1975
- this._declarations = [];
1976
- this._imports = [];
1977
- this._schemas = [];
1978
- this._activeFixtures = [];
1979
- this._testEnvAotSummaries = () => [];
1980
- this._aotSummaries = [];
1981
- this._templateOverrides = [];
1982
- this._isRoot = true;
1983
- this._rootProviderOverrides = [];
1984
- this.platform = null;
1985
- this.ngModule = null;
1986
- }
1987
- /**
1988
- * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
1989
- * angular module. These are common to every test in the suite.
1990
- *
1991
- * This may only be called once, to set up the common providers for the current test
1992
- * suite on the current platform. If you absolutely need to change the providers,
1993
- * first use `resetTestEnvironment`.
1994
- *
1995
- * Test modules and platforms for individual platforms are available from
1996
- * '@angular/<platform_name>/testing'.
1997
- */
1998
- static initTestEnvironment(ngModule, platform, summariesOrOptions) {
1999
- const testBed = _getTestBedViewEngine();
2000
- testBed.initTestEnvironment(ngModule, platform, summariesOrOptions);
2001
- return testBed;
2002
- }
2003
- /**
2004
- * Reset the providers for the test injector.
2005
- */
2006
- static resetTestEnvironment() {
2007
- _getTestBedViewEngine().resetTestEnvironment();
2008
- }
2009
- static resetTestingModule() {
2010
- _getTestBedViewEngine().resetTestingModule();
2011
- return TestBedViewEngine;
2012
- }
2013
- /**
2014
- * Allows overriding default compiler providers and settings
2015
- * which are defined in test_injector.js
2016
- */
2017
- static configureCompiler(config) {
2018
- _getTestBedViewEngine().configureCompiler(config);
2019
- return TestBedViewEngine;
2020
- }
2021
- /**
2022
- * Allows overriding default providers, directives, pipes, modules of the test injector,
2023
- * which are defined in test_injector.js
2024
- */
2025
- static configureTestingModule(moduleDef) {
2026
- _getTestBedViewEngine().configureTestingModule(moduleDef);
2027
- return TestBedViewEngine;
2028
- }
2029
- /**
2030
- * Compile components with a `templateUrl` for the test's NgModule.
2031
- * It is necessary to call this function
2032
- * as fetching urls is asynchronous.
2033
- */
2034
- static compileComponents() {
2035
- return getTestBed().compileComponents();
2036
- }
2037
- static overrideModule(ngModule, override) {
2038
- _getTestBedViewEngine().overrideModule(ngModule, override);
2039
- return TestBedViewEngine;
2040
- }
2041
- static overrideComponent(component, override) {
2042
- _getTestBedViewEngine().overrideComponent(component, override);
2043
- return TestBedViewEngine;
2044
- }
2045
- static overrideDirective(directive, override) {
2046
- _getTestBedViewEngine().overrideDirective(directive, override);
2047
- return TestBedViewEngine;
2048
- }
2049
- static overridePipe(pipe, override) {
2050
- _getTestBedViewEngine().overridePipe(pipe, override);
2051
- return TestBedViewEngine;
2052
- }
2053
- static overrideTemplate(component, template) {
2054
- _getTestBedViewEngine().overrideComponent(component, { set: { template, templateUrl: null } });
2055
- return TestBedViewEngine;
2056
- }
2057
- /**
2058
- * Overrides the template of the given component, compiling the template
2059
- * in the context of the TestingModule.
2060
- *
2061
- * Note: This works for JIT and AOTed components as well.
2062
- */
2063
- static overrideTemplateUsingTestingModule(component, template) {
2064
- _getTestBedViewEngine().overrideTemplateUsingTestingModule(component, template);
2065
- return TestBedViewEngine;
2066
- }
2067
- static overrideProvider(token, provider) {
2068
- _getTestBedViewEngine().overrideProvider(token, provider);
2069
- return TestBedViewEngine;
2070
- }
2071
- static inject(token, notFoundValue, flags) {
2072
- return _getTestBedViewEngine().inject(token, notFoundValue, flags);
2073
- }
2074
- /** @deprecated from v9.0.0 use TestBed.inject */
2075
- static get(token, notFoundValue = Injector.THROW_IF_NOT_FOUND, flags = InjectFlags.Default) {
2076
- return _getTestBedViewEngine().inject(token, notFoundValue, flags);
2077
- }
2078
- static createComponent(component) {
2079
- return _getTestBedViewEngine().createComponent(component);
2080
- }
2081
- static shouldTearDownTestingModule() {
2082
- return _getTestBedViewEngine().shouldTearDownTestingModule();
2083
- }
2084
- static tearDownTestingModule() {
2085
- _getTestBedViewEngine().tearDownTestingModule();
2086
- }
2087
- /**
2088
- * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
2089
- * angular module. These are common to every test in the suite.
2090
- *
2091
- * This may only be called once, to set up the common providers for the current test
2092
- * suite on the current platform. If you absolutely need to change the providers,
2093
- * first use `resetTestEnvironment`.
2094
- *
2095
- * Test modules and platforms for individual platforms are available from
2096
- * '@angular/<platform_name>/testing'.
2097
- */
2098
- initTestEnvironment(ngModule, platform, summariesOrOptions) {
2099
- if (this.platform || this.ngModule) {
2100
- throw new Error('Cannot set base providers because it has already been called');
2101
- }
2102
- this.platform = platform;
2103
- this.ngModule = ngModule;
2104
- if (typeof summariesOrOptions === 'function') {
2105
- this._testEnvAotSummaries = summariesOrOptions;
2106
- TestBedViewEngine._environmentTeardownOptions = undefined;
2107
- }
2108
- else {
2109
- this._testEnvAotSummaries = (summariesOrOptions === null || summariesOrOptions === void 0 ? void 0 : summariesOrOptions.aotSummaries) || (() => []);
2110
- TestBedViewEngine._environmentTeardownOptions = summariesOrOptions === null || summariesOrOptions === void 0 ? void 0 : summariesOrOptions.teardown;
2111
- }
2112
- }
2113
- /**
2114
- * Reset the providers for the test injector.
2115
- */
2116
- resetTestEnvironment() {
2117
- this.resetTestingModule();
2118
- this.platform = null;
2119
- this.ngModule = null;
2120
- this._testEnvAotSummaries = () => [];
2121
- TestBedViewEngine._environmentTeardownOptions = undefined;
2122
- }
2123
- resetTestingModule() {
2124
- ɵclearOverrides();
2125
- this._aotSummaries = [];
2126
- this._templateOverrides = [];
2127
- this._compiler = null;
2128
- this._moduleOverrides = [];
2129
- this._componentOverrides = [];
2130
- this._directiveOverrides = [];
2131
- this._pipeOverrides = [];
2132
- this._isRoot = true;
2133
- this._rootProviderOverrides = [];
2134
- this._moduleFactory = null;
2135
- this._pendingModuleFactory = null;
2136
- this._compilerOptions = [];
2137
- this._providers = [];
2138
- this._declarations = [];
2139
- this._imports = [];
2140
- this._schemas = [];
2141
- // We have to chain a couple of try/finally blocks, because each step can
2142
- // throw errors and we don't want it to interrupt the next step and we also
2143
- // want an error to be thrown at the end.
2144
- try {
2145
- this.destroyActiveFixtures();
2146
- }
2147
- finally {
2148
- try {
2149
- if (this.shouldTearDownTestingModule()) {
2150
- this.tearDownTestingModule();
2151
- }
2152
- }
2153
- finally {
2154
- this._moduleRef = null;
2155
- this._instanceTeardownOptions = undefined;
2156
- this._instantiated = false;
2157
- }
2158
- }
2159
- }
2160
- configureCompiler(config) {
2161
- this._assertNotInstantiated('TestBed.configureCompiler', 'configure the compiler');
2162
- this._compilerOptions.push(config);
2163
- }
2164
- configureTestingModule(moduleDef) {
2165
- this._assertNotInstantiated('TestBed.configureTestingModule', 'configure the test module');
2166
- if (moduleDef.providers) {
2167
- this._providers.push(...moduleDef.providers);
2168
- }
2169
- if (moduleDef.declarations) {
2170
- this._declarations.push(...moduleDef.declarations);
2171
- }
2172
- if (moduleDef.imports) {
2173
- this._imports.push(...moduleDef.imports);
2174
- }
2175
- if (moduleDef.schemas) {
2176
- this._schemas.push(...moduleDef.schemas);
2177
- }
2178
- if (moduleDef.aotSummaries) {
2179
- this._aotSummaries.push(moduleDef.aotSummaries);
2180
- }
2181
- // Always re-assign the teardown options, even if they're undefined.
2182
- // This ensures that we don't carry the options between tests.
2183
- this._instanceTeardownOptions = moduleDef.teardown;
2184
- }
2185
- compileComponents() {
2186
- if (this._moduleFactory || this._instantiated) {
2187
- return Promise.resolve(null);
2188
- }
2189
- const moduleType = this._createCompilerAndModule();
2190
- this._pendingModuleFactory = moduleType;
2191
- return this._compiler.compileModuleAndAllComponentsAsync(moduleType).then(result => {
2192
- // If the module mismatches by the time the promise resolves, it means that the module has
2193
- // already been destroyed and a new compilation has started. If that's the case, avoid
2194
- // overwriting the module factory, because it can cause downstream errors.
2195
- if (this._pendingModuleFactory === moduleType) {
2196
- this._moduleFactory = result.ngModuleFactory;
2197
- this._pendingModuleFactory = null;
2198
- }
2199
- });
2200
- }
2201
- _initIfNeeded() {
2202
- if (this._instantiated) {
2203
- return;
2204
- }
2205
- if (!this._moduleFactory) {
2206
- try {
2207
- const moduleType = this._createCompilerAndModule();
2208
- this._moduleFactory =
2209
- this._compiler.compileModuleAndAllComponentsSync(moduleType).ngModuleFactory;
2210
- }
2211
- catch (e) {
2212
- const errorCompType = this._compiler.getComponentFromError(e);
2213
- if (errorCompType) {
2214
- throw new Error(`This test module uses the component ${ɵstringify(errorCompType)} which is using a "templateUrl" or "styleUrls", but they were never compiled. ` +
2215
- `Please call "TestBed.compileComponents" before your test.`);
2216
- }
2217
- else {
2218
- throw e;
2219
- }
2220
- }
2221
- }
2222
- for (const { component, templateOf } of this._templateOverrides) {
2223
- const compFactory = this._compiler.getComponentFactory(templateOf);
2224
- ɵoverrideComponentView(component, compFactory);
2225
- }
2226
- const ngZone = new NgZone({ enableLongStackTrace: true, shouldCoalesceEventChangeDetection: false });
2227
- const providers = [{ provide: NgZone, useValue: ngZone }];
2228
- const ngZoneInjector = Injector.create({
2229
- providers: providers,
2230
- parent: this.platform.injector,
2231
- name: this._moduleFactory.moduleType.name
2232
- });
2233
- this._moduleRef = this._moduleFactory.create(ngZoneInjector);
2234
- // ApplicationInitStatus.runInitializers() is marked @internal to core. So casting to any
2235
- // before accessing it.
2236
- try {
2237
- this._moduleRef.injector.get(ApplicationInitStatus).runInitializers();
2238
- }
2239
- finally {
2240
- this._instantiated = true;
2241
- }
2242
- }
2243
- _createCompilerAndModule() {
2244
- const providers = this._providers.concat([{ provide: TestBed, useValue: this }]);
2245
- const declarations = [...this._declarations, ...this._templateOverrides.map(entry => entry.templateOf)];
2246
- const rootScopeImports = [];
2247
- const rootProviderOverrides = this._rootProviderOverrides;
2248
- if (this._isRoot) {
2249
- let RootScopeModule = class RootScopeModule {
2250
- };
2251
- RootScopeModule = __decorate([
2252
- NgModule({
2253
- providers: [
2254
- ...rootProviderOverrides,
2255
- ],
2256
- jit: true,
2257
- })
2258
- ], RootScopeModule);
2259
- rootScopeImports.push(RootScopeModule);
2260
- }
2261
- providers.push({ provide: ɵINJECTOR_SCOPE, useValue: this._isRoot ? 'root' : null });
2262
- const imports = [rootScopeImports, this.ngModule, this._imports];
2263
- const schemas = this._schemas;
2264
- let DynamicTestModule = class DynamicTestModule {
2265
- };
2266
- DynamicTestModule = __decorate([
2267
- NgModule({ providers, declarations, imports, schemas, jit: true })
2268
- ], DynamicTestModule);
2269
- const compilerFactory = this.platform.injector.get(TestingCompilerFactory);
2270
- this._compiler = compilerFactory.createTestingCompiler(this._compilerOptions);
2271
- for (const summary of [this._testEnvAotSummaries, ...this._aotSummaries]) {
2272
- this._compiler.loadAotSummaries(summary);
2273
- }
2274
- this._moduleOverrides.forEach((entry) => this._compiler.overrideModule(entry[0], entry[1]));
2275
- this._componentOverrides.forEach((entry) => this._compiler.overrideComponent(entry[0], entry[1]));
2276
- this._directiveOverrides.forEach((entry) => this._compiler.overrideDirective(entry[0], entry[1]));
2277
- this._pipeOverrides.forEach((entry) => this._compiler.overridePipe(entry[0], entry[1]));
2278
- return DynamicTestModule;
2279
- }
2280
- _assertNotInstantiated(methodName, methodDescription) {
2281
- if (this._instantiated) {
2282
- throw new Error(`Cannot ${methodDescription} when the test module has already been instantiated. ` +
2283
- `Make sure you are not using \`inject\` before \`${methodName}\`.`);
2284
- }
2285
- }
2286
- inject(token, notFoundValue, flags) {
2287
- this._initIfNeeded();
2288
- if (token === TestBed) {
2289
- return this;
2290
- }
2291
- // Tests can inject things from the ng module and from the compiler,
2292
- // but the ng module can't inject things from the compiler and vice versa.
2293
- const UNDEFINED = {};
2294
- const result = this._moduleRef.injector.get(token, UNDEFINED, flags);
2295
- return result === UNDEFINED ? this._compiler.injector.get(token, notFoundValue, flags) :
2296
- result;
2297
- }
2298
- /** @deprecated from v9.0.0 use TestBed.inject */
2299
- get(token, notFoundValue = Injector.THROW_IF_NOT_FOUND, flags = InjectFlags.Default) {
2300
- return this.inject(token, notFoundValue, flags);
2301
- }
2302
- execute(tokens, fn, context) {
2303
- this._initIfNeeded();
2304
- const params = tokens.map(t => this.inject(t));
2305
- return fn.apply(context, params);
2306
- }
2307
- overrideModule(ngModule, override) {
2308
- this._assertNotInstantiated('overrideModule', 'override module metadata');
2309
- this._moduleOverrides.push([ngModule, override]);
2310
- }
2311
- overrideComponent(component, override) {
2312
- this._assertNotInstantiated('overrideComponent', 'override component metadata');
2313
- this._componentOverrides.push([component, override]);
2314
- }
2315
- overrideDirective(directive, override) {
2316
- this._assertNotInstantiated('overrideDirective', 'override directive metadata');
2317
- this._directiveOverrides.push([directive, override]);
2318
- }
2319
- overridePipe(pipe, override) {
2320
- this._assertNotInstantiated('overridePipe', 'override pipe metadata');
2321
- this._pipeOverrides.push([pipe, override]);
2322
- }
2323
- overrideProvider(token, provider) {
2324
- this._assertNotInstantiated('overrideProvider', 'override provider');
2325
- this.overrideProviderImpl(token, provider);
2326
- }
2327
- overrideProviderImpl(token, provider, deprecated = false) {
2328
- let def = null;
2329
- if (typeof token !== 'string' && (def = ɵgetInjectableDef(token)) && def.providedIn === 'root') {
2330
- if (provider.useFactory) {
2331
- this._rootProviderOverrides.push({ provide: token, useFactory: provider.useFactory, deps: provider.deps || [] });
2332
- }
2333
- else {
2334
- this._rootProviderOverrides.push({ provide: token, useValue: provider.useValue });
2335
- }
2336
- }
2337
- let flags = 0;
2338
- let value;
2339
- if (provider.useFactory) {
2340
- flags |= 1024 /* TypeFactoryProvider */;
2341
- value = provider.useFactory;
2342
- }
2343
- else {
2344
- flags |= 256 /* TypeValueProvider */;
2345
- value = provider.useValue;
2346
- }
2347
- const deps = (provider.deps || []).map((dep) => {
2348
- let depFlags = 0 /* None */;
2349
- let depToken;
2350
- if (Array.isArray(dep)) {
2351
- dep.forEach((entry) => {
2352
- if (entry instanceof Optional) {
2353
- depFlags |= 2 /* Optional */;
2354
- }
2355
- else if (entry instanceof SkipSelf) {
2356
- depFlags |= 1 /* SkipSelf */;
2357
- }
2358
- else {
2359
- depToken = entry;
2360
- }
2361
- });
2362
- }
2363
- else {
2364
- depToken = dep;
2365
- }
2366
- return [depFlags, depToken];
2367
- });
2368
- ɵoverrideProvider({ token, flags, deps, value, deprecatedBehavior: deprecated });
2369
- }
2370
- overrideTemplateUsingTestingModule(component, template) {
2371
- this._assertNotInstantiated('overrideTemplateUsingTestingModule', 'override template');
2372
- let OverrideComponent = class OverrideComponent {
2373
- };
2374
- OverrideComponent = __decorate([
2375
- Component({ selector: 'empty', template, jit: true })
2376
- ], OverrideComponent);
2377
- this._templateOverrides.push({ component, templateOf: OverrideComponent });
2378
- }
2379
- createComponent(component) {
2380
- this._initIfNeeded();
2381
- const componentFactory = this._compiler.getComponentFactory(component);
2382
- if (!componentFactory) {
2383
- throw new Error(`Cannot create the component ${ɵstringify(component)} as it was not imported into the testing module!`);
2384
- }
2385
- // TODO: Don't cast as `InjectionToken<boolean>`, declared type is boolean[]
2386
- const noNgZone = this.inject(ComponentFixtureNoNgZone, false);
2387
- // TODO: Don't cast as `InjectionToken<boolean>`, declared type is boolean[]
2388
- const autoDetect = this.inject(ComponentFixtureAutoDetect, false);
2389
- const ngZone = noNgZone ? null : this.inject(NgZone, null);
2390
- const testComponentRenderer = this.inject(TestComponentRenderer);
2391
- const rootElId = `root${_nextRootElementId++}`;
2392
- testComponentRenderer.insertRootElement(rootElId);
2393
- const initComponent = () => {
2394
- const componentRef = componentFactory.create(Injector.NULL, [], `#${rootElId}`, this._moduleRef);
2395
- return new ComponentFixture(componentRef, ngZone, autoDetect);
2396
- };
2397
- const fixture = !ngZone ? initComponent() : ngZone.run(initComponent);
2398
- this._activeFixtures.push(fixture);
2399
- return fixture;
2400
- }
2401
- destroyActiveFixtures() {
2402
- let errorCount = 0;
2403
- this._activeFixtures.forEach((fixture) => {
2404
- try {
2405
- fixture.destroy();
2406
- }
2407
- catch (e) {
2408
- errorCount++;
2409
- console.error('Error during cleanup of component', {
2410
- component: fixture.componentInstance,
2411
- stacktrace: e,
2412
- });
2413
- }
2414
- });
2415
- this._activeFixtures = [];
2416
- if (errorCount > 0 && this.shouldRethrowTeardownErrors()) {
2417
- throw Error(`${errorCount} ${(errorCount === 1 ? 'component' : 'components')} ` +
2418
- `threw errors during cleanup`);
2419
- }
2420
- }
2421
- shouldRethrowTeardownErrors() {
2422
- var _a, _b;
2423
- const instanceOptions = this._instanceTeardownOptions;
2424
- const environmentOptions = TestBedViewEngine._environmentTeardownOptions;
2425
- // If the new teardown behavior hasn't been configured, preserve the old behavior.
2426
- if (!instanceOptions && !environmentOptions) {
2427
- return TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT;
2428
- }
2429
- // Otherwise use the configured behavior or default to rethrowing.
2430
- return (_b = (_a = instanceOptions === null || instanceOptions === void 0 ? void 0 : instanceOptions.rethrowErrors) !== null && _a !== void 0 ? _a : environmentOptions === null || environmentOptions === void 0 ? void 0 : environmentOptions.rethrowErrors) !== null && _b !== void 0 ? _b : this.shouldTearDownTestingModule();
2431
- }
2432
- shouldTearDownTestingModule() {
2433
- var _a, _b, _c, _d;
2434
- return (_d = (_b = (_a = this._instanceTeardownOptions) === null || _a === void 0 ? void 0 : _a.destroyAfterEach) !== null && _b !== void 0 ? _b : (_c = TestBedViewEngine._environmentTeardownOptions) === null || _c === void 0 ? void 0 : _c.destroyAfterEach) !== null && _d !== void 0 ? _d : TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT;
2435
- }
2436
- tearDownTestingModule() {
2437
- var _a, _b, _c, _d, _e;
2438
- // If the module ref has already been destroyed, we won't be able to get a test renderer.
2439
- if (this._moduleRef === null) {
2440
- return;
2441
- }
2442
- // Resolve the renderer ahead of time, because we want to remove the root elements as the very
2443
- // last step, but the injector will be destroyed as a part of the module ref destruction.
2444
- const testRenderer = this.inject(TestComponentRenderer);
2445
- try {
2446
- this._moduleRef.destroy();
2447
- }
2448
- catch (e) {
2449
- if ((_d = (_b = (_a = this._instanceTeardownOptions) === null || _a === void 0 ? void 0 : _a.rethrowErrors) !== null && _b !== void 0 ? _b : (_c = TestBedViewEngine._environmentTeardownOptions) === null || _c === void 0 ? void 0 : _c.rethrowErrors) !== null && _d !== void 0 ? _d : true) {
2450
- throw e;
2451
- }
2452
- else {
2453
- console.error('Error during cleanup of a testing module', {
2454
- component: this._moduleRef.instance,
2455
- stacktrace: e,
2456
- });
2457
- }
2458
- }
2459
- finally {
2460
- (_e = testRenderer === null || testRenderer === void 0 ? void 0 : testRenderer.removeAllRootElements) === null || _e === void 0 ? void 0 : _e.call(testRenderer);
2461
- }
2462
- }
2463
- }
2464
1895
  /**
2465
1896
  * @description
2466
1897
  * Configures and initializes environment for unit testing and provides methods for
@@ -2473,7 +1904,7 @@ class TestBedViewEngine {
2473
1904
  *
2474
1905
  * @publicApi
2475
1906
  */
2476
- const TestBed = ɵivyEnabled ? TestBedRender3 : TestBedViewEngine;
1907
+ const TestBed = TestBedRender3;
2477
1908
  /**
2478
1909
  * Returns a singleton of the applicable `TestBed`.
2479
1910
  *
@@ -2481,11 +1912,7 @@ const TestBed = ɵivyEnabled ? TestBedRender3 : TestBedViewEngine;
2481
1912
  *
2482
1913
  * @publicApi
2483
1914
  */
2484
- const getTestBed = ɵivyEnabled ? _getTestBedRender3 : _getTestBedViewEngine;
2485
- let testBed;
2486
- function _getTestBedViewEngine() {
2487
- return testBed = testBed || new TestBedViewEngine();
2488
- }
1915
+ const getTestBed = _getTestBedRender3;
2489
1916
  /**
2490
1917
  * Allows injecting dependencies in `beforeEach()` and `it()`.
2491
1918
  *
@@ -2568,8 +1995,8 @@ if (_global.afterEach) {
2568
1995
  }
2569
1996
  function getCleanupHook(expectedTeardownValue) {
2570
1997
  return () => {
2571
- if (TestBed.shouldTearDownTestingModule() ===
2572
- expectedTeardownValue) {
1998
+ // TODO(alxhub): find a better type here
1999
+ if (TestBed.shouldTearDownTestingModule() === expectedTeardownValue) {
2573
2000
  TestBed.resetTestingModule();
2574
2001
  resetFakeAsyncZone();
2575
2002
  }
@@ -2594,14 +2021,6 @@ const __core_private_testing_placeholder__ = '';
2594
2021
  * found in the LICENSE file at https://angular.io/license
2595
2022
  */
2596
2023
 
2597
- /**
2598
- * @license
2599
- * Copyright Google LLC All Rights Reserved.
2600
- *
2601
- * Use of this source code is governed by an MIT-style license that can be
2602
- * found in the LICENSE file at https://angular.io/license
2603
- */
2604
-
2605
2024
  /**
2606
2025
  * @license
2607
2026
  * Copyright Google LLC All Rights Reserved.
@@ -2623,5 +2042,5 @@ const __core_private_testing_placeholder__ = '';
2623
2042
  * Generated bundle index. Do not edit.
2624
2043
  */
2625
2044
 
2626
- export { ComponentFixture, ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, InjectSetupWrapper, TestBed, TestComponentRenderer, __core_private_testing_placeholder__, async, discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, getTestBed, inject, resetFakeAsyncZone, tick, waitForAsync, withModule, MetadataOverrider as ɵMetadataOverrider, TestingCompiler as ɵTestingCompiler, TestingCompilerFactory as ɵTestingCompilerFactory };
2045
+ export { ComponentFixture, ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, InjectSetupWrapper, TestBed, TestComponentRenderer, __core_private_testing_placeholder__, async, discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, getTestBed, inject, resetFakeAsyncZone, tick, waitForAsync, withModule, MetadataOverrider as ɵMetadataOverrider };
2627
2046
  //# sourceMappingURL=testing.mjs.map