@@ -15,6 +15,7 @@ import {
1515import DxList from 'devextreme/ui/list' ;
1616
1717import {
18+ DxButtonModule ,
1819 DxListModule ,
1920 DxListComponent
2021} from '../../../dist' ;
@@ -343,7 +344,7 @@ describe('DxList', () => {
343344 } ) ) ;
344345
345346
346- it ( 'should destroy all components inside template' , ( ) => {
347+ it ( 'should destroy angular components inside template' , ( ) => {
347348 let destroyed = false ;
348349 @Component ( {
349350 selector : 'destroyable-component' ,
@@ -380,4 +381,76 @@ describe('DxList', () => {
380381
381382 expect ( destroyed ) . toBe ( true ) ;
382383 } ) ;
384+
385+ it ( 'should destroy devextreme components inside template' , ( ) => {
386+ @Component ( {
387+ selector : 'test-container-component' ,
388+ template : ''
389+ } )
390+ class TestContainerComponent {
391+ items = [ 0 ] ;
392+ buttonDestroyed = false ;
393+ listVisible = true ;
394+ }
395+
396+ TestBed . configureTestingModule ( {
397+ declarations : [ TestContainerComponent ] ,
398+ imports : [ DxButtonModule , DxListModule ]
399+ } ) ;
400+
401+ TestBed . overrideComponent ( TestContainerComponent , {
402+ set : {
403+ template : `
404+ <dx-list *ngIf="listVisible" [items]="items">
405+ <div *dxTemplate="let item of 'item'">
406+ <dx-button text="Test" (onDisposing)="buttonDestroyed = true"></dx-button>
407+ </div>
408+ </dx-list>
409+ `
410+ }
411+ } ) ;
412+
413+ let fixture = TestBed . createComponent ( TestContainerComponent ) ;
414+ fixture . detectChanges ( ) ;
415+
416+ fixture . componentInstance . listVisible = false ;
417+ fixture . detectChanges ( ) ;
418+
419+ expect ( fixture . componentInstance . buttonDestroyed ) . toBe ( true ) ;
420+ } ) ;
421+
422+ it ( 'should destroy devextreme components in template root correctly' , ( ) => {
423+ @Component ( {
424+ selector : 'test-container-component' ,
425+ template : ''
426+ } )
427+ class TestContainerComponent {
428+ items = [ 0 ] ;
429+ buttonDestroyed = false ;
430+ listVisible = true ;
431+ }
432+
433+ TestBed . configureTestingModule ( {
434+ declarations : [ TestContainerComponent ] ,
435+ imports : [ DxButtonModule , DxListModule ]
436+ } ) ;
437+
438+ TestBed . overrideComponent ( TestContainerComponent , {
439+ set : {
440+ template : `
441+ <dx-list *ngIf="listVisible" [items]="items">
442+ <dx-button text="Test" (onDisposing)="buttonDestroyed = true" *dxTemplate="let item of 'item'"></dx-button>
443+ </dx-list>
444+ `
445+ }
446+ } ) ;
447+
448+ let fixture = TestBed . createComponent ( TestContainerComponent ) ;
449+ fixture . detectChanges ( ) ;
450+
451+ fixture . componentInstance . listVisible = false ;
452+ fixture . detectChanges ( ) ;
453+
454+ expect ( fixture . componentInstance . buttonDestroyed ) . toBe ( true ) ;
455+ } ) ;
383456} ) ;
0 commit comments