加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular 5:如何为数据绑定属性编写Jasmine单元测试

发布时间:2020-12-17 07:09:54 所属栏目:安全 来源:网络整理
导读:要求:我需要为 HTML元素的数据绑定属性编写单元测试. 这是代码: kendo-grid [kendoGridBinding]="gridData" [resizable]="true" style="height: 300px" kendo-grid-column field="UnitPrice" title="Unit Price" [width]="180" filter="numeric" format="{
要求:我需要为 HTML元素的数据绑定属性编写单元测试.

这是代码:

<kendo-grid
            [kendoGridBinding]="gridData"
            [resizable]="true"
            style="height: 300px">
            <kendo-grid-column
                field="UnitPrice"
                title="Unit Price"
                [width]="180"
                filter="numeric"
                format="{0:c}">
            </kendo-grid-column>
</kendo-grid>

我需要为可调整大小的属性值编写单元测试.

到目前为止我尝试了什么:

it('kendo-grid element should contain resizable attribute with "true" value',() => {
    const element = fixture.debugElement.nativeElement.querySelector('kendo-grid');
    expect(element.resizable).toBeTruthy();
  });

在运行Karma测试运行器时失败了.

enter image description here

任何帮助都会非常值得一提.

解决方法

这些属性在浏览器中转换为ng-reflect- {attributeName},因此jasmine需要查找该属性.下面的测试应该有效.

it('kendo-grid element should contain resizable attribute with "true" value',() => {
    const element = fixture.debugElement.query(By.css('kendo-grid'));
    expect(element.nativeElement.getAttribute('ng-reflect-resizable')).toBe('true');
  });

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读