|
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import {CommonModule} from '@angular/common'; |
10 | 9 | import {APP_INITIALIZER, ChangeDetectorRef, Compiler, Component, Directive, ElementRef, ErrorHandler, getNgModuleById, Inject, Injectable, InjectionToken, Injector, Input, LOCALE_ID, ModuleWithProviders, NgModule, Optional, Pipe, Type, ViewChild, ɵsetClassMetadata as setClassMetadata, ɵɵdefineComponent as defineComponent, ɵɵdefineInjector as defineInjector, ɵɵdefineNgModule as defineNgModule, ɵɵelementEnd as elementEnd, ɵɵelementStart as elementStart, ɵɵsetNgModuleScope as setNgModuleScope, ɵɵtext as text} from '@angular/core'; |
11 | | -import {getTestBed, TestBed} from '@angular/core/testing/src/test_bed'; |
| 10 | +import {TestBedImpl} from '@angular/core/testing/src/r3_test_bed'; |
| 11 | +import {TestBed} from '@angular/core/testing/src/test_bed'; |
12 | 12 | import {By} from '@angular/platform-browser'; |
13 | 13 | import {expect} from '@angular/platform-browser/testing/src/matchers'; |
14 | 14 |
|
15 | | -import {TestBedRender3} from '../testing/src/r3_test_bed'; |
16 | 15 | import {TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT, THROW_ON_UNKNOWN_ELEMENTS_DEFAULT, THROW_ON_UNKNOWN_PROPERTIES_DEFAULT} from '../testing/src/test_bed_common'; |
17 | 16 |
|
18 | 17 | const NAME = new InjectionToken<string>('name'); |
@@ -129,7 +128,7 @@ describe('TestBed', () => { |
129 | 128 | it('should apply scopes correctly for components in the lazy-loaded module', () => { |
130 | 129 | // Reset TestBed to the initial state, emulating an invocation of a first test. |
131 | 130 | // Check `TestBed.checkGlobalCompilationFinished` for additional info. |
132 | | - (getTestBed() as any)._globalCompilationChecked = false; |
| 131 | + TestBedImpl.INSTANCE.globalCompilationChecked = false; |
133 | 132 |
|
134 | 133 | @Component({ |
135 | 134 | selector: 'root', |
@@ -170,7 +169,7 @@ describe('TestBed', () => { |
170 | 169 |
|
171 | 170 | describe('TestBed with Standalone types', () => { |
172 | 171 | beforeEach(() => { |
173 | | - getTestBed().resetTestingModule(); |
| 172 | + TestBed.resetTestingModule(); |
174 | 173 | }); |
175 | 174 |
|
176 | 175 | it('should override providers on standalone component itself', () => { |
@@ -498,7 +497,7 @@ describe('TestBed with Standalone types', () => { |
498 | 497 |
|
499 | 498 | describe('TestBed', () => { |
500 | 499 | beforeEach(() => { |
501 | | - getTestBed().resetTestingModule(); |
| 500 | + TestBed.resetTestingModule(); |
502 | 501 | TestBed.configureTestingModule({imports: [HelloWorldModule]}); |
503 | 502 | }); |
504 | 503 |
|
@@ -681,15 +680,15 @@ describe('TestBed', () => { |
681 | 680 | expect(hello.nativeElement).toHaveText('Hello World!'); |
682 | 681 |
|
683 | 682 | // override the template |
684 | | - getTestBed().resetTestingModule(); |
| 683 | + TestBed.resetTestingModule(); |
685 | 684 | TestBed.configureTestingModule({imports: [HelloWorldModule]}); |
686 | 685 | TestBed.overrideComponent(GreetingCmp, {set: {template: `Bonjour {{ name }}`}}); |
687 | 686 | hello = TestBed.createComponent(HelloWorld); |
688 | 687 | hello.detectChanges(); |
689 | 688 | expect(hello.nativeElement).toHaveText('Bonjour World!'); |
690 | 689 |
|
691 | 690 | // restore the original template by calling `.resetTestingModule()` |
692 | | - getTestBed().resetTestingModule(); |
| 691 | + TestBed.resetTestingModule(); |
693 | 692 | TestBed.configureTestingModule({imports: [HelloWorldModule]}); |
694 | 693 | hello = TestBed.createComponent(HelloWorld); |
695 | 694 | hello.detectChanges(); |
@@ -1330,7 +1329,7 @@ describe('TestBed', () => { |
1330 | 1329 | class ProvidesErrorHandler { |
1331 | 1330 | } |
1332 | 1331 |
|
1333 | | - getTestBed().resetTestingModule(); |
| 1332 | + TestBed.resetTestingModule(); |
1334 | 1333 | TestBed.configureTestingModule({imports: [ProvidesErrorHandler, HelloWorldModule]}); |
1335 | 1334 |
|
1336 | 1335 | expect(TestBed.inject(ErrorHandler)).toEqual(jasmine.any(CustomErrorHandler)); |
@@ -1859,28 +1858,24 @@ describe('TestBed', () => { |
1859 | 1858 |
|
1860 | 1859 |
|
1861 | 1860 | describe('TestBed module teardown', () => { |
1862 | | - // Cast the `TestBed` to the internal data type since we're testing private APIs. |
1863 | | - let TestBed: TestBedRender3; |
1864 | | - |
1865 | 1861 | beforeEach(() => { |
1866 | | - TestBed = getTestBed() as unknown as TestBedRender3; |
1867 | 1862 | TestBed.resetTestingModule(); |
1868 | 1863 | }); |
1869 | 1864 |
|
1870 | 1865 | it('should tear down the test module by default', () => { |
1871 | | - expect(TestBed.shouldTearDownTestingModule()).toBe(true); |
| 1866 | + expect(TestBedImpl.INSTANCE.shouldTearDownTestingModule()).toBe(true); |
1872 | 1867 | }); |
1873 | 1868 |
|
1874 | 1869 | it('should be able to configure the teardown behavior', () => { |
1875 | 1870 | TestBed.configureTestingModule({teardown: {destroyAfterEach: false}}); |
1876 | | - expect(TestBed.shouldTearDownTestingModule()).toBe(false); |
| 1871 | + expect(TestBedImpl.INSTANCE.shouldTearDownTestingModule()).toBe(false); |
1877 | 1872 | }); |
1878 | 1873 |
|
1879 | 1874 | it('should reset the teardown behavior back to the default when TestBed is reset', () => { |
1880 | 1875 | TestBed.configureTestingModule({teardown: {destroyAfterEach: false}}); |
1881 | | - expect(TestBed.shouldTearDownTestingModule()).toBe(false); |
| 1876 | + expect(TestBedImpl.INSTANCE.shouldTearDownTestingModule()).toBe(false); |
1882 | 1877 | TestBed.resetTestingModule(); |
1883 | | - expect(TestBed.shouldTearDownTestingModule()).toBe(true); |
| 1878 | + expect(TestBedImpl.INSTANCE.shouldTearDownTestingModule()).toBe(true); |
1884 | 1879 | }); |
1885 | 1880 |
|
1886 | 1881 | it('should destroy test module providers when test module teardown is enabled', () => { |
@@ -2053,88 +2048,83 @@ describe('TestBed module teardown', () => { |
2053 | 2048 | }); |
2054 | 2049 |
|
2055 | 2050 | it('should rethrow errors based on the default teardown behavior', () => { |
2056 | | - expect(TestBed.shouldRethrowTeardownErrors()).toBe(TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT); |
| 2051 | + expect(TestBedImpl.INSTANCE.shouldRethrowTeardownErrors()) |
| 2052 | + .toBe(TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT); |
2057 | 2053 | }); |
2058 | 2054 |
|
2059 | 2055 | it('should rethrow errors if the option is omitted and test teardown is enabled', () => { |
2060 | 2056 | TestBed.configureTestingModule({teardown: {destroyAfterEach: true}}); |
2061 | | - expect(TestBed.shouldRethrowTeardownErrors()).toBe(true); |
| 2057 | + expect(TestBedImpl.INSTANCE.shouldRethrowTeardownErrors()).toBe(true); |
2062 | 2058 | }); |
2063 | 2059 |
|
2064 | 2060 | it('should not rethrow errors if the option is omitted and test teardown is disabled', () => { |
2065 | 2061 | TestBed.configureTestingModule({teardown: {destroyAfterEach: false}}); |
2066 | | - expect(TestBed.shouldRethrowTeardownErrors()).toBe(false); |
| 2062 | + expect(TestBedImpl.INSTANCE.shouldRethrowTeardownErrors()).toBe(false); |
2067 | 2063 | }); |
2068 | 2064 |
|
2069 | 2065 | it('should rethrow errors if the option is enabled, but teardown is disabled', () => { |
2070 | 2066 | TestBed.configureTestingModule({teardown: {destroyAfterEach: false, rethrowErrors: true}}); |
2071 | | - expect(TestBed.shouldRethrowTeardownErrors()).toBe(true); |
| 2067 | + expect(TestBedImpl.INSTANCE.shouldRethrowTeardownErrors()).toBe(true); |
2072 | 2068 | }); |
2073 | 2069 |
|
2074 | 2070 | it('should not rethrow errors if the option is disabled, but teardown is enabled', () => { |
2075 | 2071 | TestBed.configureTestingModule({teardown: {destroyAfterEach: true, rethrowErrors: false}}); |
2076 | | - expect(TestBed.shouldRethrowTeardownErrors()).toBe(false); |
| 2072 | + expect(TestBedImpl.INSTANCE.shouldRethrowTeardownErrors()).toBe(false); |
2077 | 2073 | }); |
2078 | 2074 | }); |
2079 | 2075 |
|
2080 | 2076 | describe('TestBed module `errorOnUnknownElements`', () => { |
2081 | | - // Cast the `TestBed` to the internal data type since we're testing private APIs. |
2082 | | - let TestBed: TestBedRender3; |
2083 | | - |
2084 | 2077 | beforeEach(() => { |
2085 | | - TestBed = getTestBed() as unknown as TestBedRender3; |
2086 | 2078 | TestBed.resetTestingModule(); |
2087 | 2079 | }); |
2088 | 2080 |
|
2089 | 2081 | it('should not throw based on the default behavior', () => { |
2090 | | - expect(TestBed.shouldThrowErrorOnUnknownElements()).toBe(THROW_ON_UNKNOWN_ELEMENTS_DEFAULT); |
| 2082 | + expect(TestBedImpl.INSTANCE.shouldThrowErrorOnUnknownElements()) |
| 2083 | + .toBe(THROW_ON_UNKNOWN_ELEMENTS_DEFAULT); |
2091 | 2084 | }); |
2092 | 2085 |
|
2093 | 2086 | it('should not throw if the option is omitted', () => { |
2094 | 2087 | TestBed.configureTestingModule({}); |
2095 | | - expect(TestBed.shouldThrowErrorOnUnknownElements()).toBe(false); |
| 2088 | + expect(TestBedImpl.INSTANCE.shouldThrowErrorOnUnknownElements()).toBe(false); |
2096 | 2089 | }); |
2097 | 2090 |
|
2098 | 2091 | it('should be able to configure the option', () => { |
2099 | 2092 | TestBed.configureTestingModule({errorOnUnknownElements: true}); |
2100 | | - expect(TestBed.shouldThrowErrorOnUnknownElements()).toBe(true); |
| 2093 | + expect(TestBedImpl.INSTANCE.shouldThrowErrorOnUnknownElements()).toBe(true); |
2101 | 2094 | }); |
2102 | 2095 |
|
2103 | 2096 | it('should reset the option back to the default when TestBed is reset', () => { |
2104 | 2097 | TestBed.configureTestingModule({errorOnUnknownElements: true}); |
2105 | | - expect(TestBed.shouldThrowErrorOnUnknownElements()).toBe(true); |
| 2098 | + expect(TestBedImpl.INSTANCE.shouldThrowErrorOnUnknownElements()).toBe(true); |
2106 | 2099 | TestBed.resetTestingModule(); |
2107 | | - expect(TestBed.shouldThrowErrorOnUnknownElements()).toBe(false); |
| 2100 | + expect(TestBedImpl.INSTANCE.shouldThrowErrorOnUnknownElements()).toBe(false); |
2108 | 2101 | }); |
2109 | 2102 | }); |
2110 | 2103 |
|
2111 | 2104 | describe('TestBed module `errorOnUnknownProperties`', () => { |
2112 | | - // Cast the `TestBed` to the internal data type since we're testing private APIs. |
2113 | | - let TestBed: TestBedRender3; |
2114 | | - |
2115 | 2105 | beforeEach(() => { |
2116 | | - TestBed = getTestBed() as unknown as TestBedRender3; |
2117 | 2106 | TestBed.resetTestingModule(); |
2118 | 2107 | }); |
2119 | 2108 |
|
2120 | 2109 | it('should not throw based on the default behavior', () => { |
2121 | | - expect(TestBed.shouldThrowErrorOnUnknownProperties()).toBe(THROW_ON_UNKNOWN_PROPERTIES_DEFAULT); |
| 2110 | + expect(TestBedImpl.INSTANCE.shouldThrowErrorOnUnknownProperties()) |
| 2111 | + .toBe(THROW_ON_UNKNOWN_PROPERTIES_DEFAULT); |
2122 | 2112 | }); |
2123 | 2113 |
|
2124 | 2114 | it('should not throw if the option is omitted', () => { |
2125 | 2115 | TestBed.configureTestingModule({}); |
2126 | | - expect(TestBed.shouldThrowErrorOnUnknownProperties()).toBe(false); |
| 2116 | + expect(TestBedImpl.INSTANCE.shouldThrowErrorOnUnknownProperties()).toBe(false); |
2127 | 2117 | }); |
2128 | 2118 |
|
2129 | 2119 | it('should be able to configure the option', () => { |
2130 | 2120 | TestBed.configureTestingModule({errorOnUnknownProperties: true}); |
2131 | | - expect(TestBed.shouldThrowErrorOnUnknownProperties()).toBe(true); |
| 2121 | + expect(TestBedImpl.INSTANCE.shouldThrowErrorOnUnknownProperties()).toBe(true); |
2132 | 2122 | }); |
2133 | 2123 |
|
2134 | 2124 | it('should reset the option back to the default when TestBed is reset', () => { |
2135 | 2125 | TestBed.configureTestingModule({errorOnUnknownProperties: true}); |
2136 | | - expect(TestBed.shouldThrowErrorOnUnknownProperties()).toBe(true); |
| 2126 | + expect(TestBedImpl.INSTANCE.shouldThrowErrorOnUnknownProperties()).toBe(true); |
2137 | 2127 | TestBed.resetTestingModule(); |
2138 | | - expect(TestBed.shouldThrowErrorOnUnknownProperties()).toBe(false); |
| 2128 | + expect(TestBedImpl.INSTANCE.shouldThrowErrorOnUnknownProperties()).toBe(false); |
2139 | 2129 | }); |
2140 | 2130 | }); |
0 commit comments