@@ -298,21 +298,23 @@ describe('CdkTable', () => {
298298 } ) ;
299299
300300 it ( 'should be able to show a message when no data is being displayed' , ( ) => {
301- expect ( tableElement . textContent ! . trim ( ) ) . not . toContain ( 'No data' ) ;
301+ expect ( tableElement . querySelector ( '.cdk-no-data-row' ) ) . toBeFalsy ( ) ;
302302
303303 const originalData = dataSource . data ;
304304 dataSource . data = [ ] ;
305305 fixture . detectChanges ( ) ;
306306
307- expect ( tableElement . textContent ! . trim ( ) ) . toContain ( 'No data' ) ;
307+ const noDataRow = tableElement . querySelector ( '.cdk-no-data-row' ) ! ;
308+ expect ( noDataRow ) . toBeTruthy ( ) ;
309+ expect ( noDataRow . getAttribute ( 'role' ) ) . toBe ( 'row' ) ;
308310
309311 dataSource . data = originalData ;
310312 fixture . detectChanges ( ) ;
311313
312314 // Expect it to have emitted once on init, once when empty, and again with original data.
313315 expect ( component . contentChangedCount ) . toBe ( 3 ) ;
314316
315- expect ( tableElement . textContent ! . trim ( ) ) . not . toContain ( 'No data' ) ;
317+ expect ( tableElement . querySelector ( '.cdk-no-data-row' ) ) . toBeFalsy ( ) ;
316318 } ) ;
317319
318320 it ( 'should show the no data row if there is no data on init' , ( ) => {
@@ -321,7 +323,7 @@ describe('CdkTable', () => {
321323 fixture . componentInstance . dataSource . data = [ ] ;
322324 fixture . detectChanges ( ) ;
323325 tableElement = fixture . nativeElement . querySelector ( '.cdk-table' ) ;
324- expect ( tableElement . textContent ! . trim ( ) ) . toContain ( 'No data' ) ;
326+ expect ( tableElement . querySelector ( '.cdk-no-data-row' ) ) . toBeTruthy ( ) ;
325327 expect ( component . contentChangedCount ) . toBe ( 1 ) ;
326328 } ) ;
327329 } ) ;
@@ -558,17 +560,19 @@ describe('CdkTable', () => {
558560 const dataSource = thisFixture . componentInstance . dataSource ! ;
559561 const originalData = dataSource . data ;
560562
561- expect ( tbody . textContent ! . trim ( ) ) . not . toContain ( 'No data' ) ;
563+ expect ( tbody . querySelector ( '.cdk-no-data-row' ) ) . toBeFalsy ( ) ;
562564
563565 dataSource . data = [ ] ;
564566 thisFixture . detectChanges ( ) ;
565567
566- expect ( tbody . textContent ! . trim ( ) ) . toContain ( 'No data' ) ;
568+ const noDataRow : HTMLElement = tbody . querySelector ( '.cdk-no-data-row' ) ;
569+ expect ( noDataRow ) . toBeTruthy ( ) ;
570+ expect ( noDataRow . getAttribute ( 'role' ) ) . toBe ( 'row' ) ;
567571
568572 dataSource . data = originalData ;
569573 thisFixture . detectChanges ( ) ;
570574
571- expect ( tbody . textContent ! . trim ( ) ) . not . toContain ( 'No data' ) ;
575+ expect ( tbody . querySelector ( '.cdk-no-data-row' ) ) . toBeFalsy ( ) ;
572576 } ) ;
573577
574578 it ( 'should apply correct roles for native table elements' , ( ) => {
@@ -743,7 +747,7 @@ describe('CdkTable', () => {
743747 fixture . componentInstance . dataSource . data = [ ] ;
744748 fixture . detectChanges ( ) ;
745749
746- expect ( tableElement . textContent ) . toContain ( 'No data' ) ;
750+ expect ( tableElement . querySelector ( '.cdk-no- data-row' ) ) . toBeTruthy ( ) ;
747751 } ) ;
748752
749753 describe ( 'using when predicate' , ( ) => {
@@ -2766,7 +2770,7 @@ class RowContextCdkTableApp {
27662770 </ng-container>
27672771
27682772 <cdk-row *cdkRowDef="let row; columns: columns"></cdk-row>
2769- <ng-template cdkNoDataRow>No data</ng-template >
2773+ <div * cdkNoDataRow>No data</div >
27702774 </cdk-table>
27712775 ` ,
27722776} )
0 commit comments