11import { DataSource } from '@angular/cdk/collections' ;
22import { Component , OnInit , ViewChild } from '@angular/core' ;
3- import { async , ComponentFixture , fakeAsync , flushMicrotasks , TestBed } from '@angular/core/testing' ;
3+ import {
4+ async ,
5+ ComponentFixture ,
6+ fakeAsync ,
7+ flushMicrotasks ,
8+ TestBed ,
9+ tick ,
10+ } from '@angular/core/testing' ;
411import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
512import { BehaviorSubject , Observable } from 'rxjs' ;
613import { MatPaginator , MatPaginatorModule } from '../paginator/index' ;
@@ -22,6 +29,7 @@ describe('MatTable', () => {
2229 MatTableWithSortApp ,
2330 MatTableWithPaginatorApp ,
2431 StickyTableApp ,
32+ TableWithNgContainerRow ,
2533 ] ,
2634 } ) . compileComponents ( ) ;
2735 } ) ) ;
@@ -127,6 +135,16 @@ describe('MatTable', () => {
127135 expect ( stuckCellElement . classList ) . toContain ( 'mat-table-sticky' ) ;
128136 } ) ;
129137
138+ // Note: needs to be fakeAsync so it catches the error.
139+ it ( 'should not throw when a row definition is on an ng-container' , fakeAsync ( ( ) => {
140+ const fixture = TestBed . createComponent ( TableWithNgContainerRow ) ;
141+
142+ expect ( ( ) => {
143+ fixture . detectChanges ( ) ;
144+ tick ( ) ;
145+ } ) . not . toThrow ( ) ;
146+ } ) ) ;
147+
130148 describe ( 'with MatTableDataSource and sort/pagination/filter' , ( ) => {
131149 let tableElement : HTMLElement ;
132150 let fixture : ComponentFixture < ArrayDataSourceMatTableApp > ;
@@ -750,6 +768,27 @@ class MatTableWithPaginatorApp implements OnInit {
750768 }
751769}
752770
771+ @Component ( {
772+ template : `
773+ <mat-table [dataSource]="dataSource">
774+ <ng-container matColumnDef="column_a">
775+ <mat-header-cell *matHeaderCellDef>Column A</mat-header-cell>
776+ <mat-cell *matCellDef="let row">{{row.a}}</mat-cell>
777+ </ng-container>
778+
779+ <mat-header-row *matHeaderRowDef="columnsToRender"></mat-header-row>
780+ <ng-container *matRowDef="let row; columns: columnsToRender">
781+ <mat-row></mat-row>
782+ </ng-container>
783+ </mat-table>
784+ `
785+ } )
786+ class TableWithNgContainerRow {
787+ dataSource : FakeDataSource | null = new FakeDataSource ( ) ;
788+ columnsToRender = [ 'column_a' ] ;
789+ }
790+
791+
753792function getElements ( element : Element , query : string ) : Element [ ] {
754793 return [ ] . slice . call ( element . querySelectorAll ( query ) ) ;
755794}
0 commit comments