我在寫單元測試我的角度項目,打字稿打字稿+ jasmine.createSpy()
當我試圖對某些服務創建模擬,我用這樣的方式:
const serviceMock = <IMyService>{
method: _.noop,
};
beforeEach(inject($injector => {
testingService = new AccountingService(serviceMock);
spyOn(serviceMock, 'method').and.callFake(()=>'hello');
}
該工程確定 但是當我試圖用jasmine.createSpy()
,我得到的編譯錯誤:
const serviceMock = <IMyService>{
method: jasmine.createSpy('method').and.callFake(()=>'hello'),
};
Type '{ method: Spy;}' cannot be converted to type 'MyService'. Property 'getParams' is missing in type '{ method: Spy;}'.
但getParams
是私有方法
我在做什麼錯?
它沒有幫助,但謝謝你的部分類型,這是我的新 –