【发布时间】:2017-04-10 09:26:44
【问题描述】:
组件是https://github.com/valor-software/ngx-bootstrap 下拉菜单。
在模板中我有这个:
<span dropdown placement="bottom right">
<a id="droplist-label" href="javascript:void(0)" dropdownToggle>
<span>{{conf.title}}</span>
</a>
<ul class="dropdown-menu pull-right" *dropdownMenu>
<li *ngFor="let item of items">
<a class="dropdown-item" (click)="listClick(item.value)" href="javascript:void(0)">{{item.label}}</a>
</li>
</ul>
</span>
在单击标签之前不会添加 ul - 因此我无法在测试中访问它。
调用点击:
let droplist = fixture.debugElement.query(By.css('#droplist-label')).nativeElement;
droplist.click();
不起作用 - 如果我尝试查找 dropdown-menu 它是空的:
it('should test if droplist has title', async(() => {
fixture.detectChanges();
let droplist = fixture.debugElement.query(By.css('#droplist-label')).nativeElement;
droplist.click();
fixture.whenStable().then(() => {
let droplistOptions = fixture.debugElement.queryAll(By.css('.dropdown-item'));
expect(droplistOptions.length).toBeGreaterThan(0);
});
}));
该指令似乎有一个用于单击事件的主机侦听器 - 我如何触发它以便 ul 可用?
【问题讨论】:
-
似乎组件在内部使用 - 如果您查看 内部的任何内容,queryAll 将无法正常工作。必须使用 .children 来获取元素列表。
-
对我来说同样的问题...
-
@M'sieurToph' 看看我的回答。
-
谢谢 ... 看看我的 ;)
标签: angular jasmine karma-jasmine