1- import { Component } from '@angular/core' ;
1+ import { Component , signal } from '@angular/core' ;
22import { ComponentFixture , TestBed } from '@angular/core/testing' ;
33import { HarnessLoader , parallel } from '@angular/cdk/testing' ;
44import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed' ;
@@ -176,11 +176,24 @@ describe('MatTableHarness', () => {
176176 symbol : 'H' ,
177177 } ) ;
178178 } ) ;
179+
180+ it ( 'should be able to get the "no data" row' , async ( ) => {
181+ const table = await loader . getHarness ( MatTableHarness ) ;
182+ expect ( await table . getNoDataRow ( ) ) . toBe ( null ) ;
183+
184+ fixture . componentInstance . dataSource . set ( [ ] ) ;
185+ const row = await table . getNoDataRow ( ) ;
186+ const cells = await row ?. getCells ( ) ;
187+
188+ expect ( row ) . toBeTruthy ( ) ;
189+ expect ( cells ?. length ) . toBe ( 1 ) ;
190+ expect ( await cells ?. [ 0 ] . getText ( ) ) . toBe ( 'No data' ) ;
191+ } ) ;
179192} ) ;
180193
181194@Component ( {
182195 template : `
183- <table mat-table [dataSource]="dataSource">
196+ <table mat-table [dataSource]="dataSource() ">
184197 <ng-container matColumnDef="position">
185198 <th mat-header-cell *matHeaderCellDef>No.</th>
186199 <td mat-cell *matCellDef="let element">{{element.position}}</td>
@@ -208,13 +221,17 @@ describe('MatTableHarness', () => {
208221 <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
209222 <tr mat-footer-row *matFooterRowDef="displayedColumns"></tr>
210223 <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
224+
225+ <tr *matNoDataRow>
226+ <td>No data</td>
227+ </tr>
211228 </table>
212229 ` ,
213230 imports : [ MatTableModule ] ,
214231} )
215232class TableHarnessTest {
216233 displayedColumns : string [ ] = [ 'position' , 'name' , 'weight' , 'symbol' ] ;
217- dataSource = [
234+ dataSource = signal ( [
218235 { position : 1 , name : 'Hydrogen' , weight : 1.0079 , symbol : 'H' } ,
219236 { position : 2 , name : 'Helium' , weight : 4.0026 , symbol : 'He' } ,
220237 { position : 3 , name : 'Lithium' , weight : 6.941 , symbol : 'Li' } ,
@@ -225,5 +242,5 @@ class TableHarnessTest {
225242 { position : 8 , name : 'Oxygen' , weight : 15.9994 , symbol : 'O' } ,
226243 { position : 9 , name : 'Fluorine' , weight : 18.9984 , symbol : 'F' } ,
227244 { position : 10 , name : 'Neon' , weight : 20.1797 , symbol : 'Ne' } ,
228- ] ;
245+ ] ) ;
229246}
0 commit comments