@@ -30,6 +30,7 @@ describe('CdkTable', () => {
3030 DuplicateColumnDefNameCdkTableApp ,
3131 MissingColumnDefCdkTableApp ,
3232 CrazyColumnNameCdkTableApp ,
33+ UndefinedColumnsCdkTableApp ,
3334 ] ,
3435 } ) . compileComponents ( ) ;
3536 } ) ) ;
@@ -133,6 +134,21 @@ describe('CdkTable', () => {
133134 . toThrowError ( getTableUnknownColumnError ( 'column_a' ) . message ) ;
134135 } ) ;
135136
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+
136152 it ( 'should be able to dynamically add/remove column definitions' , ( ) => {
137153 const dynamicColumnDefFixture = TestBed . createComponent ( DynamicColumnDefinitionsCdkTableApp ) ;
138154 dynamicColumnDefFixture . detectChanges ( ) ;
@@ -753,6 +769,24 @@ class MissingColumnDefCdkTableApp {
753769 dataSource : FakeDataSource = new FakeDataSource ( ) ;
754770}
755771
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+
756790@Component ( {
757791 template : `
758792 <cdk-table [dataSource]="dataSource">
0 commit comments