From 86c46908d442c28defb3f7b351edb2c14a1f07ae Mon Sep 17 00:00:00 2001 From: Andrew Kushnir Date: Tue, 21 May 2019 16:54:10 -0700 Subject: [PATCH] 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 --- packages/core/src/metadata/resource_loading.ts | 2 +- packages/core/test/test_bed_spec.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/core/src/metadata/resource_loading.ts b/packages/core/src/metadata/resource_loading.ts index ce4d7be738..c9ae16a81b 100644 --- a/packages/core/src/metadata/resource_loading.ts +++ b/packages/core/src/metadata/resource_loading.ts @@ -103,7 +103,7 @@ export function isComponentDefPendingResolution(type: Type): 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, Component> { diff --git a/packages/core/test/test_bed_spec.ts b/packages/core/test/test_bed_spec.ts index fa546d6ac1..56dfc65ea0 100644 --- a/packages/core/test/test_bed_spec.ts +++ b/packages/core/test/test_bed_spec.ts @@ -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')