@@ -296,21 +296,23 @@ describe('CdkTable', () => {
296296 } ) ;
297297
298298 it ( 'should be able to show a message when no data is being displayed' , ( ) => {
299- expect ( tableElement . textContent ! . trim ( ) ) . not . toContain ( 'No data' ) ;
299+ expect ( tableElement . querySelector ( '.cdk-no-data-row' ) ) . toBeFalsy ( ) ;
300300
301301 const originalData = dataSource . data ;
302302 dataSource . data = [ ] ;
303303 fixture . detectChanges ( ) ;
304304
305- expect ( tableElement . textContent ! . trim ( ) ) . toContain ( 'No data' ) ;
305+ const noDataRow = tableElement . querySelector ( '.cdk-no-data-row' ) ! ;
306+ expect ( noDataRow ) . toBeTruthy ( ) ;
307+ expect ( noDataRow . getAttribute ( 'role' ) ) . toBe ( 'row' ) ;
306308
307309 dataSource . data = originalData ;
308310 fixture . detectChanges ( ) ;
309311
310312 // Expect it to have emitted once on init, once when empty, and again with original data.
311313 expect ( component . contentChangedCount ) . toBe ( 3 ) ;
312314
313- expect ( tableElement . textContent ! . trim ( ) ) . not . toContain ( 'No data' ) ;
315+ expect ( tableElement . querySelector ( '.cdk-no-data-row' ) ) . toBeFalsy ( ) ;
314316 } ) ;
315317
316318 it ( 'should show the no data row if there is no data on init' , ( ) => {
@@ -319,7 +321,7 @@ describe('CdkTable', () => {
319321 fixture . componentInstance . dataSource . data = [ ] ;
320322 fixture . detectChanges ( ) ;
321323 tableElement = fixture . nativeElement . querySelector ( '.cdk-table' ) ;
322- expect ( tableElement . textContent ! . trim ( ) ) . toContain ( 'No data' ) ;
324+ expect ( tableElement . querySelector ( '.cdk-no-data-row' ) ) . toBeTruthy ( ) ;
323325 expect ( component . contentChangedCount ) . toBe ( 1 ) ;
324326 } ) ;
325327 } ) ;
@@ -562,17 +564,19 @@ describe('CdkTable', () => {
562564 const dataSource = thisFixture . componentInstance . dataSource ! ;
563565 const originalData = dataSource . data ;
564566
565- expect ( tbody . textContent ! . trim ( ) ) . not . toContain ( 'No data' ) ;
567+ expect ( tbody . querySelector ( '.cdk-no-data-row' ) ) . toBeFalsy ( ) ;
566568
567569 dataSource . data = [ ] ;
568570 thisFixture . detectChanges ( ) ;
569571
570- expect ( tbody . textContent ! . trim ( ) ) . toContain ( 'No data' ) ;
572+ const noDataRow : HTMLElement = tbody . querySelector ( '.cdk-no-data-row' ) ;
573+ expect ( noDataRow ) . toBeTruthy ( ) ;
574+ expect ( noDataRow . getAttribute ( 'role' ) ) . toBe ( 'row' ) ;
571575
572576 dataSource . data = originalData ;
573577 thisFixture . detectChanges ( ) ;
574578
575- expect ( tbody . textContent ! . trim ( ) ) . not . toContain ( 'No data' ) ;
579+ expect ( tbody . querySelector ( '.cdk-no-data-row' ) ) . toBeFalsy ( ) ;
576580 } ) ;
577581
578582 it ( 'should apply correct roles for native table elements' , ( ) => {
@@ -741,7 +745,7 @@ describe('CdkTable', () => {
741745 fixture . componentInstance . dataSource . data = [ ] ;
742746 fixture . detectChanges ( ) ;
743747
744- expect ( tableElement . textContent ) . toContain ( 'No data' ) ;
748+ expect ( tableElement . querySelector ( '.cdk-no- data-row' ) ) . toBeTruthy ( ) ;
745749 } ) ;
746750
747751 describe ( 'using when predicate' , ( ) => {
@@ -2677,7 +2681,7 @@ class RowContextCdkTableApp {
26772681 </ng-container>
26782682
26792683 <cdk-row *cdkRowDef="let row; columns: columns"></cdk-row>
2680- <ng-template cdkNoDataRow>No data</ng-template >
2684+ <div * cdkNoDataRow>No data</div >
26812685 </cdk-table>
26822686 `
26832687} )
0 commit comments