dec*_*bal 8 jasmine angular-material angular
当我尝试测试为 Angular Material 设置值的组件方法时MatPaginator,出现以下错误:
TypeError: Cannot set property 'pageIndex' of undefined
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
成分:
resetVacancySearch = () => {
this.isVacanciesSearchMode = false;
this.searchVacanciesValue = '';
this.paginatorVacancies.pageIndex = 0; // reset to the first page
this.paginatorVacancies.pageSize = 10;
this.getVacanciesList(0, 10, 'name', 'ASC');
}
Run Code Online (Sandbox Code Playgroud)
测试文件:
it('should call sourcingService.getVacanciesList and reset the search value from the input field', () => {
spyOn(sourcingService, 'getVacanciesList').and.returnValue(Observable.of());
component.resetVacancySearch();
expect(sourcingService.getVacanciesList).toHaveBeenCalledWith(0, 10, 'name', 'ASC');
expect(component.searchVacanciesValue).toEqual('');
});
Run Code Online (Sandbox Code Playgroud)
该应用程序工作正常,但我无法将 MatPaginator 的实例放入测试文件中。有人可以告诉我如何模拟 MatPaginator 进行测试吗?谢谢!
只需添加
MatPaginatorModule,
BrowserAnimationsModule
Run Code Online (Sandbox Code Playgroud)
在 import[] 数组中。
| 归档时间: |
|
| 查看次数: |
8052 次 |
| 最近记录: |