refactor(ivy): create an Ivy version of tree-shakable providers test (#28477)
Due to the fact that the test in 'ng_module_integration_spec.ts' relied on internal VE data structures (the '_def' field) to verify the state and the structure has changed in Ivy, this commit adds an Ivy version of the same test. PR Close #28477
This commit is contained in:
parent
36902e2f0e
commit
8930f60a4b
@ -14,7 +14,7 @@ import {NgModuleData} from '@angular/core/src/view/types';
|
|||||||
import {tokenKey} from '@angular/core/src/view/util';
|
import {tokenKey} from '@angular/core/src/view/util';
|
||||||
import {ComponentFixture, TestBed, inject} from '@angular/core/testing';
|
import {ComponentFixture, TestBed, inject} from '@angular/core/testing';
|
||||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||||
import {fixmeIvy, modifiedInIvy, obsoleteInIvy} from '@angular/private/testing';
|
import {fixmeIvy, modifiedInIvy, obsoleteInIvy, onlyInIvy} from '@angular/private/testing';
|
||||||
|
|
||||||
import {InternalNgModuleRef, NgModuleFactory} from '../../src/linker/ng_module_factory';
|
import {InternalNgModuleRef, NgModuleFactory} from '../../src/linker/ng_module_factory';
|
||||||
import {clearModulesForTest} from '../../src/linker/ng_module_factory_loader';
|
import {clearModulesForTest} from '../../src/linker/ng_module_factory_loader';
|
||||||
@ -1316,7 +1316,7 @@ function declareTests(config?: {useJit: boolean}) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('tree shakable providers', () => {
|
describe('tree shakable providers', () => {
|
||||||
fixmeIvy('FW-794: NgModuleDefinition not exposed on NgModuleData')
|
modifiedInIvy('Ivy and VE have different internal fields to access providers')
|
||||||
.it('definition should not persist across NgModuleRef instances', () => {
|
.it('definition should not persist across NgModuleRef instances', () => {
|
||||||
@NgModule()
|
@NgModule()
|
||||||
class SomeModule {
|
class SomeModule {
|
||||||
@ -1347,6 +1347,36 @@ function declareTests(config?: {useJit: boolean}) {
|
|||||||
(ngModuleRef2 as NgModuleData)._def.providersByKey[tokenKey(Bar)];
|
(ngModuleRef2 as NgModuleData)._def.providersByKey[tokenKey(Bar)];
|
||||||
expect(providerDef2).toBeUndefined();
|
expect(providerDef2).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onlyInIvy(`Ivy and VE have different internal fields to access providers`)
|
||||||
|
.it('definition should not persist across NgModuleRef instances', () => {
|
||||||
|
@NgModule()
|
||||||
|
class SomeModule {
|
||||||
|
}
|
||||||
|
|
||||||
|
class Bar {
|
||||||
|
static ngInjectableDef: InjectableDef<Bar> = defineInjectable({
|
||||||
|
factory: () => new Bar(),
|
||||||
|
providedIn: SomeModule,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const factory = createModuleFactory(SomeModule);
|
||||||
|
const ngModuleRef1 = factory.create(null);
|
||||||
|
|
||||||
|
// Inject a tree shakeable provider token.
|
||||||
|
ngModuleRef1.injector.get(Bar);
|
||||||
|
|
||||||
|
// Tree Shakeable provider definition should be available.
|
||||||
|
const providerDef1 = (ngModuleRef1 as any)._r3Injector.records.get(Bar);
|
||||||
|
expect(providerDef1).not.toBeUndefined();
|
||||||
|
|
||||||
|
// Instantiate the same module. The tree shakeable provider definition should not be
|
||||||
|
// present.
|
||||||
|
const ngModuleRef2 = factory.create(null);
|
||||||
|
const providerDef2 = (ngModuleRef2 as any)._r3Injector.records.get(Bar);
|
||||||
|
expect(providerDef2).toBeUndefined();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user