@@ -23,6 +23,7 @@ describe('MDC-based MatTable', () => {
23
23
MatTableApp ,
24
24
MatTableWithWhenRowApp ,
25
25
ArrayDataSourceMatTableApp ,
26
+ NativeHtmlTableApp ,
26
27
MatTableWithSortApp ,
27
28
MatTableWithPaginatorApp ,
28
29
StickyTableApp ,
@@ -81,6 +82,21 @@ describe('MDC-based MatTable', () => {
81
82
] ) ;
82
83
} ) ;
83
84
85
+ it ( 'should be able to render a table correctly with native elements' , ( ) => {
86
+ let fixture = TestBed . createComponent ( NativeHtmlTableApp ) ;
87
+ fixture . detectChanges ( ) ;
88
+
89
+ const tableElement = fixture . nativeElement . querySelector ( 'table' ) ;
90
+ const data = fixture . componentInstance . dataSource ! . data ;
91
+ expectTableToMatchContent ( tableElement , [
92
+ [ 'Column A' , 'Column B' , 'Column C' ] ,
93
+ [ data [ 0 ] . a , data [ 0 ] . b , data [ 0 ] . c ] ,
94
+ [ data [ 1 ] . a , data [ 1 ] . b , data [ 1 ] . c ] ,
95
+ [ data [ 2 ] . a , data [ 2 ] . b , data [ 2 ] . c ] ,
96
+ [ data [ 3 ] . a , data [ 3 ] . b , data [ 3 ] . c ] ,
97
+ ] ) ;
98
+ } ) ;
99
+
84
100
it ( 'should be able to nest tables' , ( ) => {
85
101
const fixture = TestBed . createComponent ( NestedTableApp ) ;
86
102
fixture . detectChanges ( ) ;
@@ -96,6 +112,28 @@ describe('MDC-based MatTable', () => {
96
112
expect ( innerRows . map ( row => row . cells . length ) ) . toEqual ( [ 3 , 3 , 3 , 3 ] ) ;
97
113
} ) ;
98
114
115
+ it ( 'should be able to show a message when no data is being displayed in a native table' , ( ) => {
116
+ const fixture = TestBed . createComponent ( NativeHtmlTableApp ) ;
117
+ fixture . detectChanges ( ) ;
118
+
119
+ // Assert that the data is inside the tbody specifically.
120
+ const tbody = fixture . nativeElement . querySelector ( 'tbody' ) ! ;
121
+ const dataSource = fixture . componentInstance . dataSource ! ;
122
+ const initialData = dataSource . data ;
123
+
124
+ expect ( tbody . textContent . trim ( ) ) . not . toContain ( 'No data' ) ;
125
+
126
+ dataSource . data = [ ] ;
127
+ fixture . detectChanges ( ) ;
128
+
129
+ expect ( tbody . textContent . trim ( ) ) . toContain ( 'No data' ) ;
130
+
131
+ dataSource . data = initialData ;
132
+ fixture . detectChanges ( ) ;
133
+
134
+ expect ( tbody . textContent . trim ( ) ) . not . toContain ( 'No data' ) ;
135
+ } ) ;
136
+
99
137
it ( 'should be able to show a message when no data is being displayed' , ( ) => {
100
138
const fixture = TestBed . createComponent ( MatTableApp ) ;
101
139
fixture . detectChanges ( ) ;
@@ -601,6 +639,39 @@ class MatTableApp {
601
639
@ViewChild ( MatTable ) table : MatTable < TestData > ;
602
640
}
603
641
642
+ @Component ( {
643
+ template : `
644
+ <table mat-table [dataSource]="dataSource">
645
+ <ng-container matColumnDef="column_a">
646
+ <th mat-header-cell *matHeaderCellDef> Column A</th>
647
+ <td mat-cell *matCellDef="let row"> {{row.a}}</td>
648
+ </ng-container>
649
+
650
+ <ng-container matColumnDef="column_b">
651
+ <th mat-header-cell *matHeaderCellDef> Column B</th>
652
+ <td mat-cell *matCellDef="let row"> {{row.b}}</td>
653
+ </ng-container>
654
+
655
+ <ng-container matColumnDef="column_c">
656
+ <th mat-header-cell *matHeaderCellDef> Column C</th>
657
+ <td mat-cell *matCellDef="let row"> {{row.c}}</td>
658
+ </ng-container>
659
+
660
+ <tr mat-header-row *matHeaderRowDef="columnsToRender"></tr>
661
+ <tr mat-row *matRowDef="let row; columns: columnsToRender"></tr>
662
+ <tr *matNoDataRow>
663
+ <td>No data</td>
664
+ </tr>
665
+ </table>
666
+ `
667
+ } )
668
+ class NativeHtmlTableApp {
669
+ dataSource : FakeDataSource | null = new FakeDataSource ( ) ;
670
+ columnsToRender = [ 'column_a' , 'column_b' , 'column_c' ] ;
671
+
672
+ @ViewChild ( MatTable ) table : MatTable < TestData > ;
673
+ }
674
+
604
675
@Component ( {
605
676
template : `
606
677
<table mat-table [dataSource]="dataSource">
0 commit comments