1
1
import { DataSource } from '@angular/cdk/collections' ;
2
2
import { 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' ;
4
11
import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
5
12
import { BehaviorSubject , Observable } from 'rxjs' ;
6
13
import { MatPaginator , MatPaginatorModule } from '../paginator/index' ;
@@ -22,6 +29,7 @@ describe('MatTable', () => {
22
29
MatTableWithSortApp ,
23
30
MatTableWithPaginatorApp ,
24
31
StickyTableApp ,
32
+ TableWithNgContainerRow ,
25
33
] ,
26
34
} ) . compileComponents ( ) ;
27
35
} ) ) ;
@@ -127,6 +135,16 @@ describe('MatTable', () => {
127
135
expect ( stuckCellElement . classList ) . toContain ( 'mat-table-sticky' ) ;
128
136
} ) ;
129
137
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
+
130
148
describe ( 'with MatTableDataSource and sort/pagination/filter' , ( ) => {
131
149
let tableElement : HTMLElement ;
132
150
let fixture : ComponentFixture < ArrayDataSourceMatTableApp > ;
@@ -750,6 +768,27 @@ class MatTableWithPaginatorApp implements OnInit {
750
768
}
751
769
}
752
770
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
+
753
792
function getElements ( element : Element , query : string ) : Element [ ] {
754
793
return [ ] . slice . call ( element . querySelectorAll ( query ) ) ;
755
794
}
0 commit comments