it('should check if all div are appearing which are dependent on a common condition', () => {
component.someCommonCondition = true;
fixture.detectChanges();
// now the prob lies in line below since it only gets the first element of the mentioned class
const contentCheck = fixture.debugElement.query(By.css('.someClass'))
expect() // what to write here to check all 3 divs are getting rendered
})
<div *ngif="someCommonCondition" class="someClass"></div>
<div *ngif="someCommonCondition" class="someClass"></div>
<div *ngif="someCommonCondition" class="someClass"></div>
問候,我正在嘗試撰寫一個單元測驗,我可以測驗是否有多個 div 被渲染,這取決于一個常見的條件。我想知道是否有辦法在一個測驗中做到這一點,而不是單獨為每個測驗撰寫測驗,因為它們都依賴于一個共同的條件。也就是說,它們要么都不出現,要么都應該出現。
uj5u.com熱心網友回復:
我認為您可以使用queryAll而不是query. queryAll將回傳一個陣列。
嘗試以下操作:
it('should check if all div are appearing which are dependent on a common condition', () => {
component.someCommonCondition = true;
fixture.detectChanges();
// now the prob lies in line below since it only gets the first element of the mentioned class
const contentChecks = fixture.debugElement.queryAll(By.css('.someClass'))
expect(contentChecks.length).toBe(3);
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/428392.html
標籤:javascript angularjs 打字稿 单元测试 茉莉花
