简体   繁体   English

在spec.ts Angular4中获取类元素的长度

[英]Getting class elements length in spec.ts Angular4

I have a simple spec.ts, where i am getting an array from service. 我有一个简单的说明,从服务中获取阵列。 Same service render a table in *ngFor inside the component. 相同的服务在组件内部的* ngFor中呈现一个表。 Table- tr has a class .dataTr . Tabletr具有一个.dataTr类。 How can i know how much tr are in the table. 我怎么知道表中有多少tr。

I tried this. 我试过了

it('Should increase page number on paginator next Click', async(() => {   

    fixture.detectChanges();
    fixture.whenStable().then(() => { 
        fixture.detectChanges();
        console.log(component.dataSource.length);
        let tr = fixture.debugElement.query(By.css('.dataTr'))[1];
        console.log(tr);
        expect(2 + 2).toBe(4);
    });


}));
let numTrs = fixture.debugElement.queryAll(By.css('tr')).length;
expect(numTrs).toBe(/* Expected Number */);

or if you want to search only within the table: 或者,如果您只想在表格中搜索:

let tableDe = fixture.debugElement.query(By.css('.dataTr'));
expect(tableDe.queryAll(By.css('tr')).length).toBe(/* Expected Number */);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM