单元测试排序"/>
使用 MatSort 在 Angular 中进行单元测试排序
我目前在尝试测试 Angular 项目中的排序功能时遇到问题。 我不明白为什么在浏览 HTML 时我无法获得任何“表格”元素。 我正在尝试使用 MatSort 测试排序。
.html 的片段:
<div class="table-wrapper">
<div class="loader-shade" *ngIf="isLoading">
<mat-spinner *ngIf="isLoading"></mat-spinner>
</div>
<table mat-table="mat-table" #table="" [dataSource]="dataSource" matSort="matSort">
<ng-container matColumnDef="column1">
<th mat-header-cell="" *matHeaderCellDef="" mat-sort-header="">COLUMN1</th>
<td mat-cell="mat-cell" *matCellDef=""></td>
</ng-container>
<ng-container matColumnDef="column2">
<th mat-header-cell="" *matHeaderCellDef="" mat-sort-header="">COLUMN2</th>
<td mat-cell="mat-cell" *matCellDef=""></td>
</ng-container>
</table>
</div>
.spec.ts 文件的片段:
it('should sort by row clicked', () => {
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
const table = compiled.querySelector('table');
console.log('Table : ' + table);
});
当我运行当前测试类时,日志返回一个空的 HTMLTableElement,因此我无法继续检索我正在寻找的
th
以测试排序。
任何建议或帮助将不胜感激!
我已经尝试过这里的建议:How to test MatSort with Jasmine 但它没有帮助。
我也尝试遵循这样的事情:ponent.spec.ts 但它也没有帮助.
回答如下:更多推荐
使用 MatSort 在 Angular 中进行单元测试排序
发布评论