diff --git a/src/material-experimental/mdc-tabs/tab-group.spec.ts b/src/material-experimental/mdc-tabs/tab-group.spec.ts index f3a8659804ce..adabc86bf284 100644 --- a/src/material-experimental/mdc-tabs/tab-group.spec.ts +++ b/src/material-experimental/mdc-tabs/tab-group.spec.ts @@ -280,6 +280,18 @@ describe('MatTabGroup', () => { .toHaveBeenCalledWith(jasmine.objectContaining({index: 0})); }); + it('should clean up the tabs QueryList on destroy', () => { + const component: MatTabGroup = + fixture.debugElement.query(By.css('mat-tab-group'))!.componentInstance; + const spy = jasmine.createSpy('complete spy'); + const subscription = component._tabs.changes.subscribe({complete: spy}); + + fixture.destroy(); + + expect(spy).toHaveBeenCalled(); + subscription.unsubscribe(); + }); + }); describe('aria labelling', () => { diff --git a/src/material/tabs/tab-group.spec.ts b/src/material/tabs/tab-group.spec.ts index 390265cfe281..c452f6498827 100644 --- a/src/material/tabs/tab-group.spec.ts +++ b/src/material/tabs/tab-group.spec.ts @@ -279,6 +279,18 @@ describe('MatTabGroup', () => { .toHaveBeenCalledWith(jasmine.objectContaining({index: 0})); }); + it('should clean up the tabs QueryList on destroy', () => { + const component: MatTabGroup = + fixture.debugElement.query(By.css('mat-tab-group'))!.componentInstance; + const spy = jasmine.createSpy('complete spy'); + const subscription = component._tabs.changes.subscribe({complete: spy}); + + fixture.destroy(); + + expect(spy).toHaveBeenCalled(); + subscription.unsubscribe(); + }); + }); describe('aria labelling', () => { diff --git a/src/material/tabs/tab-group.ts b/src/material/tabs/tab-group.ts index fd9318bfc627..6b46072a6005 100644 --- a/src/material/tabs/tab-group.ts +++ b/src/material/tabs/tab-group.ts @@ -297,6 +297,7 @@ export abstract class _MatTabGroupBase extends _MatTabGroupMixinBase implements } ngOnDestroy() { + this._tabs.destroy(); this._tabsSubscription.unsubscribe(); this._tabLabelSubscription.unsubscribe(); }