@@ -94,6 +94,13 @@ describe('CdkTable', () => {
9494 } ) ;
9595 } ) ;
9696
97+ it ( 'should disconnect the data source when table is destroyed' , ( ) => {
98+ expect ( dataSource . isConnected ) . toBe ( true ) ;
99+
100+ fixture . destroy ( ) ;
101+ expect ( dataSource . isConnected ) . toBe ( false ) ;
102+ } ) ;
103+
97104 it ( 'should not clobber an existing table role' , ( ) => {
98105 fixture = TestBed . createComponent ( CustomRoleCdkTableApp ) ;
99106 fixture . detectChanges ( ) ;
@@ -301,8 +308,10 @@ describe('CdkTable', () => {
301308 ] ) ;
302309
303310 // Add a data source that has initialized data. Expect that the table shows this data.
304- component . dataSource = new FakeDataSource ( ) ;
311+ const dynamicDataSource = new FakeDataSource ( ) ;
312+ component . dataSource = dynamicDataSource ;
305313 fixture . detectChanges ( ) ;
314+ expect ( dynamicDataSource . isConnected ) . toBe ( true ) ;
306315
307316 let data = component . dataSource . data ;
308317 expect ( tableElement ) . toMatchTableContent ( [
@@ -315,6 +324,9 @@ describe('CdkTable', () => {
315324 // Remove the data source and check to make sure the table is empty again.
316325 component . dataSource = null ;
317326 fixture . detectChanges ( ) ;
327+
328+ // Expect that the old data source has been disconnected.
329+ expect ( dynamicDataSource . isConnected ) . toBe ( false ) ;
318330 expect ( tableElement ) . toMatchTableContent ( [
319331 [ 'Column A' ]
320332 ] ) ;
@@ -454,6 +466,10 @@ class FakeDataSource extends DataSource<TestData> {
454466 return map . call ( combineLatest ( streams ) , ( [ data ] ) => data ) ;
455467 }
456468
469+ disconnect ( ) {
470+ this . isConnected = false ;
471+ }
472+
457473 addData ( ) {
458474 const nextIndex = this . data . length + 1 ;
459475
0 commit comments