3
我有以下功能進行單元測試。我在元件中使用了帶有查看子元件的文本框元素,並且在測試中,我需要在調用setTimeout()
之後測試我的文本框是否被聚焦。如何檢查我的元素是否集中在角度4的單元測試中?
@ViewChild('searchInput') searchInput: ElementRef;
function A(show) {
const self = this;
if (show) {
this.xyz= true;
setTimeout(function() {
self.searchInput.nativeElement.focus();
}, 0);
} else {
self.xyz= false;
self.abc = '';
}
}
這裏是我想我的測試案例:
it('textbox get focus toggleSearch', async(() => {
let el: DebugElement;
component.toggleSearch(true);
el = fixture.debugElement.query(By.css('#search-input-theme'));
let native: HTMLElement = el.nativeElement;
spyOn(native,'focus');
fixture.whenStable().then(() => {
expect(native.focus).toHaveBeenCalled();
});
}));
您的規格文件在哪裏? –
代碼已更新@AmitChigadani – Pranjal