我尝试了以下方法,例如:
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [CmpBeingTested],
providers: [
{provide: window, useValue: window}
]
});
}));
我无法覆盖CmpBeingTested构造函数:
constructor(@Inject('Window') private _window: Window) { }
我一直收到错误
没有Window的提供者!
答案 0 :(得分:0)
beforeEach(async(() => {
let windowMock: Window = { } as any;
TestBed.configureTestingModule({
declarations: [CmpBeingTested],
providers: [
{ provide: 'Window', useFactory: (() => { return windowMock; }) }
]
});
}));