@@ -30,6 +30,7 @@ describe('CdkTable', () => {
30
30
DuplicateColumnDefNameCdkTableApp ,
31
31
MissingColumnDefCdkTableApp ,
32
32
CrazyColumnNameCdkTableApp ,
33
+ UndefinedColumnsCdkTableApp ,
33
34
] ,
34
35
} ) . compileComponents ( ) ;
35
36
} ) ) ;
@@ -133,6 +134,21 @@ describe('CdkTable', () => {
133
134
. toThrowError ( getTableUnknownColumnError ( 'column_a' ) . message ) ;
134
135
} ) ;
135
136
137
+ it ( 'should not throw an error if columns are undefined on initialization' , ( ) => {
138
+ const undefinedColumnsFixture = TestBed . createComponent ( UndefinedColumnsCdkTableApp ) ;
139
+ undefinedColumnsFixture . detectChanges ( ) ;
140
+
141
+ tableElement = undefinedColumnsFixture . nativeElement . querySelector ( 'cdk-table' ) ;
142
+
143
+ expect ( getHeaderRow ( tableElement ) ) . toBeNull ( 'Should be no header without cells' ) ;
144
+
145
+ // Rows should be empty since there are no columns to display.
146
+ const rows = getRows ( tableElement ) ;
147
+ expect ( rows [ 0 ] . textContent ) . toBe ( '' ) ;
148
+ expect ( rows [ 1 ] . textContent ) . toBe ( '' ) ;
149
+ expect ( rows [ 2 ] . textContent ) . toBe ( '' ) ;
150
+ } ) ;
151
+
136
152
it ( 'should be able to dynamically add/remove column definitions' , ( ) => {
137
153
const dynamicColumnDefFixture = TestBed . createComponent ( DynamicColumnDefinitionsCdkTableApp ) ;
138
154
dynamicColumnDefFixture . detectChanges ( ) ;
@@ -753,6 +769,24 @@ class MissingColumnDefCdkTableApp {
753
769
dataSource : FakeDataSource = new FakeDataSource ( ) ;
754
770
}
755
771
772
+ @Component ( {
773
+ template : `
774
+ <cdk-table [dataSource]="dataSource">
775
+ <ng-container cdkColumnDef="column_a">
776
+ <cdk-header-cell *cdkHeaderCellDef> Column A</cdk-header-cell>
777
+ <cdk-cell *cdkCellDef="let row"> {{row.a}}</cdk-cell>
778
+ </ng-container>
779
+
780
+ <cdk-header-row *cdkHeaderRowDef="undefinedColumns"></cdk-header-row>
781
+ <cdk-row *cdkRowDef="let row; columns: undefinedColumns"></cdk-row>
782
+ </cdk-table>
783
+ `
784
+ } )
785
+ class UndefinedColumnsCdkTableApp {
786
+ undefinedColumns ;
787
+ dataSource : FakeDataSource = new FakeDataSource ( ) ;
788
+ }
789
+
756
790
@Component ( {
757
791
template : `
758
792
<cdk-table [dataSource]="dataSource">
0 commit comments