@@ -16,14 +16,21 @@ import { NgHttpLoaderComponent } from '../../lib/components/ng-http-loader.compo
1616import { PendingInterceptorServiceInterceptor } from '../../lib/services/pending-interceptor.service' ;
1717import { SpinnerVisibilityService } from '../../lib/services/spinner-visibility.service' ;
1818import { Spinkit , SPINKIT_COMPONENTS } from '../../lib/spinkits' ;
19+ import { Component } from '@angular/core' ;
20+
21+ @Component ( {
22+ template : '<ng-http-loader id="http-loader"></ng-http-loader>'
23+ } )
24+ export class ComponentWithLoaderComponent {
25+ }
1926
2027describe ( 'NgHttpLoaderComponent' , ( ) => {
2128 let component : NgHttpLoaderComponent ;
2229 let fixture : ComponentFixture < NgHttpLoaderComponent > ;
2330
2431 beforeEach ( async ( ( ) => {
2532 TestBed . configureTestingModule ( {
26- declarations : [ NgHttpLoaderComponent , ...SPINKIT_COMPONENTS ] ,
33+ declarations : [ NgHttpLoaderComponent , ComponentWithLoaderComponent , ...SPINKIT_COMPONENTS ] ,
2734 imports : [ HttpClientTestingModule ] ,
2835 providers : [ PendingInterceptorServiceInterceptor ]
2936 } )
@@ -33,7 +40,6 @@ describe('NgHttpLoaderComponent', () => {
3340 beforeEach ( ( ) => {
3441 fixture = TestBed . createComponent ( NgHttpLoaderComponent ) ;
3542 component = fixture . componentInstance ;
36- component . ngOnInit ( ) ;
3743 } ) ;
3844
3945 it ( 'should create the ng-http-loader component' , ( ) => {
@@ -52,6 +58,19 @@ describe('NgHttpLoaderComponent', () => {
5258 expect ( element . className ) . toBe ( 'sk-cube-grid colored' ) ;
5359 } ) ;
5460
61+ it ( 'should destroy ng-http-loader as a view dependency without error' , ( ) => {
62+ const fixtureWithLoader = TestBed . createComponent ( ComponentWithLoaderComponent ) ;
63+ const componentWithLoader = fixtureWithLoader . componentInstance ;
64+ expect ( componentWithLoader ) . toBeTruthy ( ) ;
65+
66+ const element = fixtureWithLoader
67+ . debugElement
68+ . query ( By . css ( '#http-loader' ) ) ;
69+ expect ( element ) . toBeTruthy ( ) ;
70+
71+ // There shouldn't be any errors in the console when the testbed cleans up the component.
72+ } ) ;
73+
5574 it ( 'should not set the colored class if background-color is defined' , ( ) => {
5675 component . isSpinnerVisible = true ;
5776 component . backgroundColor = '#ff0000' ;
@@ -282,7 +301,6 @@ describe('NgHttpLoaderComponent', () => {
282301
283302 const newFixture = TestBed . createComponent ( NgHttpLoaderComponent ) ;
284303 const newComponent = newFixture . componentInstance ;
285- newComponent . ngOnInit ( ) ;
286304
287305 tick ( ) ;
288306 expect ( newComponent . isSpinnerVisible ) . toBeTruthy ( ) ;
0 commit comments