我正在尝试为一个下拉列表编写单元测试,并在其顶部与搜索框相关联。问题是valueChanges没有被解雇,并且我看不到filteredValues
施加断言。我看到搜索框已更新为值“ S2”,但没有看到调用组件的valueChanges。非常感谢我在这里做错什么。
单元测试:
it('should search for stores',fakeAsync(() => {
initTest('add');
fixture.detectChanges();
fixture.nativeElement.querySelector('#select').click();
fixture.detectChanges();
const d = overlayContainer.getcontainerElement().querySelector('#search');
d.textContent = 'S2';
d.dispatchEvent(new Event('input'));
flush();
fixture.detectChanges();
fixture.whenStable().then(() => {
component.filteredValues.subscribe(value => {
console.log('Value :: ' + JSON.stringify(value));
});
});
}));
内部组件:
this.search.valueChanges.pipe(takeUntil(this._destroyed)).subscribe(searchText => {
this.filteredValues = of(this.filterValue(searchText));
});