查看代码并提供清晰的说明。
@HostListener('document:click',[$event])
clickout(event){
if(event.target.className!=='some blah some blah'){
if(this.dropdownlist && this.dropdownlist.nativeElement){
if(!this.dropdownlist.nativeElement.contains(event.target)){
this.somehandlingdropdown(true);
}
}
}
}
欢迎您加入。
您可以在测试中创建事件:
const event = new KeyboardEvent('keydown', {
key: 'ArrowDown',
altKey: true
});
document.dispatchEvent(event);
fixture.detectChanges();
类似:
it('should test the clickout function', () => {
const event = { target: { className: 'some blah some bah'} };
component.clickout(event);
expect(component.somehandlingdropdown).toBeFalsy(); <-- what ever
your set value here check toBeTrue or toBeFalsy
});