我在写单元测试我的角度项目,打字稿打字稿+ 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
是私有方法
我在做什么错?
它没有帮助,但谢谢你的部分类型,这是我的新 –