Skip to content

Commit 86c4690

Browse files
AndrewKushnirjasonaden
authored andcommitted
fix(ivy): R3TestBed doesn't allow template overrides with an empty string (angular#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 angular#30602
1 parent fa6cbb3 commit 86c4690

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

packages/core/src/metadata/resource_loading.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function isComponentDefPendingResolution(type: Type<any>): boolean {
103103

104104
export function componentNeedsResolution(component: Component): boolean {
105105
return !!(
106-
(component.templateUrl && !component.template) ||
106+
(component.templateUrl && !component.hasOwnProperty('template')) ||
107107
component.styleUrls && component.styleUrls.length);
108108
}
109109
export function clearResolutionOfComponentResourcesQueue(): Map<Type<any>, Component> {

packages/core/test/test_bed_spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,14 @@ describe('TestBed', () => {
423423
const fixture = TestBed.createComponent(SomeComponent);
424424
expect(fixture.nativeElement.innerHTML).toBe('Template override');
425425
});
426+
427+
it('should have an ability to override template with empty string', () => {
428+
const SomeComponent = getAOTCompiledComponent();
429+
TestBed.configureTestingModule({declarations: [SomeComponent]});
430+
TestBed.overrideTemplateUsingTestingModule(SomeComponent, '');
431+
const fixture = TestBed.createComponent(SomeComponent);
432+
expect(fixture.nativeElement.innerHTML).toBe('');
433+
});
426434
});
427435

428436
onlyInIvy('patched ng defs should be removed after resetting TestingModule')

0 commit comments

Comments
 (0)