diff --git a/src/modules/testing/mocks/mock-media-query.service.ts b/src/modules/testing/mocks/mock-media-query.service.ts index d084ed094..69c3b5ddc 100644 --- a/src/modules/testing/mocks/mock-media-query.service.ts +++ b/src/modules/testing/mocks/mock-media-query.service.ts @@ -26,11 +26,11 @@ export class MockSkyMediaQueryService extends SkyMediaQueryService { this._currentBreakpoints = breakpoints; } - private _currentBreakpoints: SkyMediaBreakpoints = SkyMediaBreakpoints.md; - - private currentMockSubject: BehaviorSubject + public currentMockSubject: BehaviorSubject = new BehaviorSubject(this.current); + private _currentBreakpoints: SkyMediaBreakpoints = SkyMediaBreakpoints.md; + constructor() { super(new NgZone({enableLongStackTrace: true})); } diff --git a/src/modules/tiles/tile-dashboard/tile-dashboard.service.spec.ts b/src/modules/tiles/tile-dashboard/tile-dashboard.service.spec.ts index 468638156..119ce42f2 100644 --- a/src/modules/tiles/tile-dashboard/tile-dashboard.service.spec.ts +++ b/src/modules/tiles/tile-dashboard/tile-dashboard.service.spec.ts @@ -403,11 +403,9 @@ describe('Tile dashboard service', () => { it( 'should release resources when destroyed', inject([SkyTileDashboardService], (dashboardService: SkyTileDashboardService) => { - let destroySpy = spyOn(mockMediaQueryService, 'destroy'); - dashboardService.destroy(); - expect(destroySpy).toHaveBeenCalled(); + expect(mockMediaQueryService.currentMockSubject.observers.length).toBe(0); }) ); }); diff --git a/src/modules/tiles/tile-dashboard/tile-dashboard.service.ts b/src/modules/tiles/tile-dashboard/tile-dashboard.service.ts index 9b21f98de..7f3de60b7 100644 --- a/src/modules/tiles/tile-dashboard/tile-dashboard.service.ts +++ b/src/modules/tiles/tile-dashboard/tile-dashboard.service.ts @@ -7,6 +7,8 @@ import { } from '@angular/core'; import { DragulaService } from 'ng2-dragula/ng2-dragula'; +import { Subscription } from 'rxjs'; + import { SkyMediaBreakpoints, SkyMediaQueryService @@ -58,6 +60,8 @@ export class SkyTileDashboardService { private singleColumn: SkyTileDashboardColumnComponent; + private mediaSubscription: Subscription; + constructor( private dragulaService: DragulaService, private mediaQuery: SkyMediaQueryService @@ -146,8 +150,8 @@ export class SkyTileDashboardService { public destroy() { /*istanbul ignore else */ - if (this.mediaQuery) { - this.mediaQuery.destroy(); + if (this.mediaSubscription) { + this.mediaSubscription.unsubscribe(); } } @@ -322,7 +326,7 @@ export class SkyTileDashboardService { } private initMediaQueries() { - this.mediaQuery.subscribe( + this.mediaSubscription = this.mediaQuery.subscribe( (args: SkyMediaBreakpoints) => { this.changeColumnMode(args === SkyMediaBreakpoints.xs || args === SkyMediaBreakpoints.sm); }