@@ -94,6 +94,13 @@ describe('CdkTable', () => {
94
94
} ) ;
95
95
} ) ;
96
96
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
+
97
104
it ( 'should not clobber an existing table role' , ( ) => {
98
105
fixture = TestBed . createComponent ( CustomRoleCdkTableApp ) ;
99
106
fixture . detectChanges ( ) ;
@@ -301,8 +308,10 @@ describe('CdkTable', () => {
301
308
] ) ;
302
309
303
310
// 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 ;
305
313
fixture . detectChanges ( ) ;
314
+ expect ( dynamicDataSource . isConnected ) . toBe ( true ) ;
306
315
307
316
let data = component . dataSource . data ;
308
317
expect ( tableElement ) . toMatchTableContent ( [
@@ -315,6 +324,9 @@ describe('CdkTable', () => {
315
324
// Remove the data source and check to make sure the table is empty again.
316
325
component . dataSource = null ;
317
326
fixture . detectChanges ( ) ;
327
+
328
+ // Expect that the old data source has been disconnected.
329
+ expect ( dynamicDataSource . isConnected ) . toBe ( false ) ;
318
330
expect ( tableElement ) . toMatchTableContent ( [
319
331
[ 'Column A' ]
320
332
] ) ;
@@ -454,6 +466,10 @@ class FakeDataSource extends DataSource<TestData> {
454
466
return map . call ( combineLatest ( streams ) , ( [ data ] ) => data ) ;
455
467
}
456
468
469
+ disconnect ( ) {
470
+ this . isConnected = false ;
471
+ }
472
+
457
473
addData ( ) {
458
474
const nextIndex = this . data . length + 1 ;
459
475
0 commit comments