首页 > 解决方案 > 相同的字符串为 toMatch() 方法 Jasmine 抛出错误

问题描述

我正在尝试为下拉列表编写测试用例

测试用例一工作正常。但是对于测试用例二,我面临错误

我尝试了方法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');
    });

在此处输入图像描述

标签: javascriptarraysjasmineangular5karma-jasmine

解决方案


推荐阅读