@@ -144,14 +144,15 @@ describe('ViewContainerRef', () => {
144144
145145 // Add a test component to the view container ref to ensure that
146146 // the "ng-container" comment was used as marker for the insertion.
147- vcref . createComponent ( HelloComp ) ;
147+ const ref = vcref . createComponent ( HelloComp ) ;
148148 fixture . detectChanges ( ) ;
149149
150150 expect ( testParent . textContent ) . toBe ( 'hello' ) ;
151151 expect ( testParent . childNodes . length ) . toBe ( 2 ) ;
152152 expect ( testParent . childNodes [ 0 ] . nodeType ) . toBe ( Node . ELEMENT_NODE ) ;
153153 expect ( testParent . childNodes [ 0 ] . textContent ) . toBe ( 'hello' ) ;
154154 expect ( testParent . childNodes [ 1 ] . nodeType ) . toBe ( Node . COMMENT_NODE ) ;
155+ ref . destroy ( ) ;
155156 } ) ;
156157
157158 it ( 'should support attribute selectors in dynamically created components' , ( ) => {
@@ -167,7 +168,7 @@ describe('ViewContainerRef', () => {
167168 @ViewChild ( 'container' , { read : ViewContainerRef } ) vcRef ! : ViewContainerRef ;
168169
169170 createComponent ( ) {
170- this . vcRef . createComponent ( HelloComp ) ;
171+ return this . vcRef . createComponent ( HelloComp ) ;
171172 }
172173 }
173174
@@ -176,9 +177,10 @@ describe('ViewContainerRef', () => {
176177 fixture . detectChanges ( ) ;
177178 expect ( fixture . debugElement . nativeElement . innerHTML ) . not . toContain ( 'Hello' ) ;
178179
179- fixture . componentInstance . createComponent ( ) ;
180+ const ref = fixture . componentInstance . createComponent ( ) ;
180181 fixture . detectChanges ( ) ;
181182 expect ( fixture . debugElement . nativeElement . innerHTML ) . toContain ( 'Hello' ) ;
183+ ref . destroy ( ) ;
182184 } ) ;
183185
184186 it ( 'should view queries in dynamically created components' , ( ) => {
@@ -294,11 +296,11 @@ describe('ViewContainerRef', () => {
294296 ) { }
295297
296298 createComponentViaVCRef ( ) {
297- this . vcRef . createComponent ( HelloComp ) ;
299+ return this . vcRef . createComponent ( HelloComp ) ;
298300 }
299301
300302 createComponentViaFactory ( ) {
301- createComponent ( HelloComp , {
303+ return createComponent ( HelloComp , {
302304 environmentInjector : this . injector ,
303305 hostElement : this . elementRef . nativeElement . querySelector ( '#factory' ) ,
304306 } ) ;
@@ -308,8 +310,8 @@ describe('ViewContainerRef', () => {
308310 TestBed . configureTestingModule ( { declarations : [ TestComp , HelloComp ] } ) ;
309311 const fixture = TestBed . createComponent ( TestComp ) ;
310312 fixture . detectChanges ( ) ;
311- fixture . componentInstance . createComponentViaVCRef ( ) ;
312- fixture . componentInstance . createComponentViaFactory ( ) ;
313+ const firstRef = fixture . componentInstance . createComponentViaVCRef ( ) ;
314+ const secondRef = fixture . componentInstance . createComponentViaFactory ( ) ;
313315 fixture . detectChanges ( ) ;
314316
315317 // Verify host element for a component created via `vcRef.createComponent` method
@@ -336,6 +338,8 @@ describe('ViewContainerRef', () => {
336338 // Make sure selector-based attrs and classes were not added to the host element
337339 expect ( factoryHostElement . classList . contains ( 'class-a' ) ) . toBe ( false ) ;
338340 expect ( factoryHostElement . getAttribute ( 'attr-c' ) ) . toBe ( null ) ;
341+ firstRef . destroy ( ) ;
342+ secondRef . destroy ( ) ;
339343 } ) ;
340344 } ) ;
341345
@@ -1534,6 +1538,7 @@ describe('ViewContainerRef', () => {
15341538 fixture . componentInstance . viewContainerRef . createComponent ( DynamicComponent ) ;
15351539 const element = componentRef . location . nativeElement ;
15361540 expect ( ( element . namespaceURI || '' ) . toLowerCase ( ) ) . not . toContain ( 'svg' ) ;
1541+ componentRef . destroy ( ) ;
15371542 } ) ;
15381543
15391544 it ( 'should be compatible with componentRef generated via TestBed.createComponent in component factory' , ( ) => {
0 commit comments