【发布时间】:2020-09-03 16:16:52
【问题描述】:
我的组件中有这个服务,它的方法之一是动态调用的
@Input methodName: string;
constructor(
private readonly testService: testService
) {
}
loadData() {
this.testService[this.methodName]().subscribe();
}
我
我在测试方法 loadData() 时遇到了很多麻烦,它一直告诉我 this.testService[methodName] 不起作用,您将如何测试这种方法?
it('should ', fakeAsync(() => {
// getData is the supposed methodName that has to be set;
testService.getData.and.returnValue(asyncData({} as any));
component.loadData();
flush();
expect(testService.getData).toHaveBeenCalled();
}));
【问题讨论】:
-
如果答案对你有用,请告诉我
-
@ShashankVivek 成功了,谢谢!你将如何继续模拟组件?
-
试试medium.com/@shashankvivek.7/…,如果这就是你要找的,请告诉我
-
也欢迎投票 :)
标签: angular typescript unit-testing jasmine karma-jasmine