默认情况下,我有一个处于禁用状态的搜索按钮,直到选择了用户和功能或选择了功能和客户,此按钮才被启用。因此,当我编写测试用例时,我尝试选择用户和功能,并尝试检查按钮是否启用。但是那个测试用例没有说false,而当我给not.disabled时,它就成真了。以同样的方式我想检查load的禁用状态,它正在传递,然后当我运行not.disabled时,它失败。相当奇怪的行为。
html:
<div class="buttons">
<button mat-button name="search" class="search" [ngClass]="{'disable-search-btn' : !isSearchEnabled}">search</button>
</div>
spec.ts
it('should check customer dropdown values are present and search button is enabled', () => {
component.openFunctionBasedField(component.functionOptions[1]);
component.onSelectCustomer(component.customerOptions[0]);
expect(component.isCustomerFunctionSelected).toBeTruthy();
expect(component.customerOptions.length).toBeGreaterThan(0);
const searchButton = fixture.debugElement.query(By.css('.search')).nativeElement.disabled;
});
ts:
toggleSearchButton() {
if ((this.selectedFunctionItem && (this.selectedUser && this.selectedUser.length > 0)) || this.selectedCustomerItem) {
this.isSearchEnabled = true;
} else {
this.isSearch = false;
this.isSearchEnabled = false;
}
}