微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过 selectedRowIndex

如何解决通过 selectedRowIndex

我正在尝试通过选择 angular 11 中的 rowIndex 来测试启用或禁用按钮,它在 expect(component.deleteRoleButtondisabled).toBeFalse(); 中失败;并且永远如此!你们有什么想法吗?

HTML:

<tr class="roles-list" mat-row *matRowDef="let row; columns: displayedColumns;"
           (click)="highlight(row)" [ngClass]="{'highlight': selectedRowIndex == row.id}" 
           id="highlightRow"></tr>

TS:

selectedRowIndex: number | undefined;
deleteRoleButtondisabled = true;

highlight(row: RoleAssignmentTableRowData) {
this.selectedRowIndex = row.id;
this.deleteRoleButtondisabled = false;
}

规格:

it('should enable delete role button if one role is selected',() => {

     component.selectedRowIndex = 1;
     expect(component.selectedRowIndex).toBe(1);
     expect(component.highlight).toBeTrue();
     expect(component.deleteRoleButtondisabled).toBeFalse(); // this goes to be always true!
   });

解决方法

highlight(...) 是在您的测试中根本没有触发的点击事件上调用的,因此没有理由将 deleteRoleButtonDisabled 变为 false。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。