fix(ivy): R3TestBed doesn't allow template overrides with an empty string (#30602)
Prior to this change a component was considered unresolved (i.e. having dynamic resources that should be loaded, like external template or stylesheets) even if template override was provided as an empty string (for example, via TestBed.overrideTemplateUsingTestingModule call). This commit fixes the condition that previously treated empty string as an absent template value. PR Close #30602
This commit is contained in:
parent
fa6cbb3ffe
commit
86c46908d4
|
@ -103,7 +103,7 @@ export function isComponentDefPendingResolution(type: Type<any>): boolean {
|
|||
|
||||
export function componentNeedsResolution(component: Component): boolean {
|
||||
return !!(
|
||||
(component.templateUrl && !component.template) ||
|
||||
(component.templateUrl && !component.hasOwnProperty('template')) ||
|
||||
component.styleUrls && component.styleUrls.length);
|
||||
}
|
||||
export function clearResolutionOfComponentResourcesQueue(): Map<Type<any>, Component> {
|
||||
|
|
|
@ -423,6 +423,14 @@ describe('TestBed', () => {
|
|||
const fixture = TestBed.createComponent(SomeComponent);
|
||||
expect(fixture.nativeElement.innerHTML).toBe('Template override');
|
||||
});
|
||||
|
||||
it('should have an ability to override template with empty string', () => {
|
||||
const SomeComponent = getAOTCompiledComponent();
|
||||
TestBed.configureTestingModule({declarations: [SomeComponent]});
|
||||
TestBed.overrideTemplateUsingTestingModule(SomeComponent, '');
|
||||
const fixture = TestBed.createComponent(SomeComponent);
|
||||
expect(fixture.nativeElement.innerHTML).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
onlyInIvy('patched ng defs should be removed after resetting TestingModule')
|
||||
|
|
Loading…
Reference in New Issue