我有一个要测试的函数。我在其中使用matpaginator.firstpage()方法。但是,我为此功能编写的任何测试我都会出错
"Cannot read property 'firstPage' of undefined"
我找不到有关如何在单元测试中模拟童形嘲笑或在我的规格文件中提供的任何内容,以允许该测试完成。
任何帮助/建议/技巧将不胜感激。
it('area of business selected should be in active Filter Chip Object', () => {
component.selectedBusinessArea = 'Fake Business';
component.activeFilterChips = [];
component.activeFilterObj = {};
fixture.detectChanges();
fixture.whenStable().then(() => {
spyOn(component.paginator, 'firstPage').and.returnValue('');
component.startFilter();
fixture.detectChanges();
expect(component.activeFilterChips).toBe([{
option: "businessArea",
value: "Fake Business"
}]);
})
});
为paginator创建一个为第一个页面()创建间谍,并将其包装在wheStable()内部的测试通过。不确定这是否是正确处理它的正确方法。另外,我不是要测试第一个页面(),所以我给了"。