【发布时间】:2017-11-24 00:34:27
【问题描述】:
我正在使用 Typescript 为我的 Angular 项目编写单元测试
当我尝试为某些服务创建模拟时,我使用这种方式:
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 是MyService 的私有方法
我做错了什么?
【问题讨论】:
标签: angular typescript unit-testing jasmine