0
我想測試下拉切換功能。但我無法實現它的工作。我還將BsDropdownModule
導入了spec文件。 注意:我正在使用ngx-bootstrap。如何在角度2測試中測試下拉式切換操作?
這裏是我的嘗試:
HTML:
<div class="btnBox" dropdown placement="bottom right">
<button class="btnIcon dropdown-toggle" dropdownToggle>
</button>
<ul class="btnOptionBox dropdown-menu dropdown-menu-right" *dropdownMenu>
<li class="iconBtn" (click)="someFun()" type="button"><span>Edit</span></li>
<li class="iconBtn" (click)="someFun1()" type="button"><span>Delete</span></li>
</ul>
</div>
測試規格:
it("Should show options when toggle option is clicked",() => {
fixture.detectChanges();
let toggleButton = fixture.debugElement.queryAll(By.css('[dropdownToggle]'));
toggleButton[0].nativeElement.click();
fixture.detectChanges();
/*Unable to access li tag directly. That's why I have used it's parent*/
let list = fixture.debugElement.queryAll(By.css('div.ellipsisBox'));
console.log(list[0]); /*Shows the list in the children array*/
console.log(list[0].children); /*Doesn't show the list*/
});
任何人都可以提出這樣做的正確方法?