test(ivy): add compiler.getModuleId support in R3TestBed (#28097)
This update brings `getModuleId` function support to R3TestBed-specific Compiler instance. PR Close #28097
This commit is contained in:
parent
9a81f0d9a8
commit
da1d19b40f
|
@ -634,6 +634,11 @@ export class TestBedRender3 implements Injector, TestBed {
|
||||||
return Object.keys(overrides).length ? {...meta, ...overrides} : meta;
|
return Object.keys(overrides).length ? {...meta, ...overrides} : meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
_getModuleResolver() { return this._resolvers.module; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
|
@ -764,5 +769,8 @@ class R3TestCompiler implements Compiler {
|
||||||
|
|
||||||
clearCacheFor(type: Type<any>): void {}
|
clearCacheFor(type: Type<any>): void {}
|
||||||
|
|
||||||
getModuleId(moduleType: Type<any>): string|undefined { return undefined; }
|
getModuleId(moduleType: Type<any>): string|undefined {
|
||||||
|
const meta = this.testBed._getModuleResolver().resolve(moduleType);
|
||||||
|
return meta && meta.id || undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,20 +80,19 @@ if (isBrowser) {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Compiler', () => {
|
describe('Compiler', () => {
|
||||||
fixmeIvy('FW-855: TestBed.get(Compiler) should return TestBed-specific Compiler instance')
|
it('should return NgModule id when asked', () => {
|
||||||
.it('should return NgModule id when asked', () => {
|
@NgModule({
|
||||||
@NgModule({
|
id: 'test-module',
|
||||||
id: 'test-module',
|
})
|
||||||
})
|
class TestModule {
|
||||||
class TestModule {
|
}
|
||||||
}
|
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TestModule],
|
imports: [TestModule],
|
||||||
});
|
});
|
||||||
const compiler = TestBed.get(Compiler) as Compiler;
|
const compiler = TestBed.get(Compiler) as Compiler;
|
||||||
expect(compiler.getModuleId(TestModule)).toBe('test-module');
|
expect(compiler.getModuleId(TestModule)).toBe('test-module');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('errors', () => {
|
describe('errors', () => {
|
||||||
|
|
|
@ -457,28 +457,25 @@ class CompWithUrlTemplate {
|
||||||
expect(TestBed.get('a')).toBe('mockA: depValue');
|
expect(TestBed.get('a')).toBe('mockA: depValue');
|
||||||
});
|
});
|
||||||
|
|
||||||
fixmeIvy('FW-855: TestBed.get(Compiler) should return TestBed-specific Compiler instance')
|
it('should support SkipSelf', () => {
|
||||||
.it('should support SkipSelf', () => {
|
@NgModule({
|
||||||
@NgModule({
|
providers: [
|
||||||
providers: [
|
{provide: 'a', useValue: 'aValue'},
|
||||||
{provide: 'a', useValue: 'aValue'},
|
{provide: 'dep', useValue: 'depValue'},
|
||||||
{provide: 'dep', useValue: 'depValue'},
|
]
|
||||||
]
|
})
|
||||||
})
|
class MyModule {
|
||||||
class MyModule {
|
}
|
||||||
}
|
|
||||||
|
|
||||||
TestBed.overrideProvider(
|
TestBed.overrideProvider(
|
||||||
'a',
|
'a', {useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new SkipSelf(), 'dep']]});
|
||||||
{useFactory: (dep: any) => `mockA: ${dep}`, deps: [[new SkipSelf(), 'dep']]});
|
TestBed.configureTestingModule(
|
||||||
TestBed.configureTestingModule(
|
{providers: [{provide: 'dep', useValue: 'parentDepValue'}]});
|
||||||
{providers: [{provide: 'dep', useValue: 'parentDepValue'}]});
|
|
||||||
|
|
||||||
const compiler = TestBed.get(Compiler) as Compiler;
|
const compiler = TestBed.get(Compiler) as Compiler;
|
||||||
const modFactory = compiler.compileModuleSync(MyModule);
|
const modFactory = compiler.compileModuleSync(MyModule);
|
||||||
expect(modFactory.create(getTestBed()).injector.get('a'))
|
expect(modFactory.create(getTestBed()).injector.get('a')).toBe('mockA: parentDepValue');
|
||||||
.toBe('mockA: parentDepValue');
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('should keep imported NgModules eager', () => {
|
it('should keep imported NgModules eager', () => {
|
||||||
let someModule: SomeModule|undefined;
|
let someModule: SomeModule|undefined;
|
||||||
|
|
Loading…
Reference in New Issue