1 回答
TA贡献1828条经验 获得超4个赞
您需要window以不同的方式使用对象来覆盖默认行为
在你的component.ts
export class SomeComponent{
compWindow: any;
constructor(){
this.compWindow = window;
}
toggleFloatingFilter() {
this.hasFloatingFilter = !this.hasFloatingFilter;
this.clearSelectedRows();
this.gridApi.setRowData(this.rowData);
if (!this.hasFloatingFilter) {
this.gridApi.setFilterModel(null);
this.loadData();
}
setTimeout(() => {
this.gridApi.refreshHeader();
}, 0);
this.compWindow.location.reload(); // access like this
}
}
然后在spec文件中:
const myWindow = {
location: {
reload() { return 'something'; }
}
};
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [BrowserModule],
declarations: [SomeComponent],
providers:
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(SomeComponent);
component = fixture.componentInstance;
component.compWindow = myWindow; // this would override the value we are setting in constructor.
fixture.detectChanges(); // once we have overridden it, now call "detectChanges"
});
}));
添加回答
举报