javascript - 相同的字符串为 toMatch() 方法 Jasmine 抛出错误
问题描述
我正在尝试为下拉列表编写测试用例
- 测试用例一:如果 values.length > 0 然后用列表填充下拉列表
- 测试用例二:如果 values.length ===0 则显示 NO RESULTS FOUND
测试用例一工作正常。但是对于测试用例二,我面临错误
我尝试了方法toContain() , toEqual()。但没有运气。下面是它的代码。
HTML
<p id="noResultFound" *ngIf="values.length === 0" class="k-popup filter-search-list">No Results Found</p>
组件.sepc.ts 文件
[![it('should show "No Results Found" if options are not listed', () => {
const fixture = TestBed.createComponent(SearchSelectComponent);
const comp = fixture.componentInstance;
comp.show = true;
comp.values = \[\];
comp.field = 'SearchList';
comp.placeholder = "search for company";
fixture.detectChanges();
const compiled = fixture.nativeElement;
expect(comp.values).toEqual(\[\])
//getting error at below line
expect(compiled.querySelector('#noResultFound').textContent).toMatch('No Result Found');
});
解决方案
推荐阅读
- java - Android,无法解析 ImageDecoder
- android - android kotlin 片段操作栏标题
- python - 几乎相同的副本,只是长度不同
- python - 使用 Python 3 从列表中生成所有可能的顺序字符串
- smartcard - chipTAN:没有 PIN 怎么可能?
- c# - Linq Select with Or 语句 VS 单独的查询
- c# - Visual Studio 2012 Resharper 菜单不显示
- python-3.x - 使用地图作为随机森林分类器的输入
- swift - “StorageMetadata”类型的值没有成员“downloadURL”
- excel - 运行excel宏后出现神秘的数据连接