【发布时间】:2018-03-29 04:49:42
【问题描述】:
您好,我正在Angular JS 开发 Web 应用程序。我正在使用Jasmine 框架编写单元测试用例。我正在尝试模拟一些服务。我无法使用多个参数调用服务。下面是我的单元测试代码。
it('update is allowed false', async(() => {
let service = fixture.debugElement.injector.get(UserOnboardEndpointMock);
spyOn(service, 'updateUser').and.callThrough();
fixture.whenStable().then(() => {
expect(service.updateUser).toHaveBeenCalledWith(jasmine.any(true,"101"));
})
}));
以下是我的服务。
updateUser<T>(event: boolean, userid: string): Observable<T>{
var updateUserResult = { result: true } as any;
return Observable.of<T>(updateUserResult);
}
我尝试如下调用服务,但没有任何结果。
expect(service.updateUser).toHaveBeenCalledWith(true,"101");
expect(service.updateUser).toHaveBeenCalledWith([true]["101"]);
有人可以帮我调用我的模拟服务吗?任何帮助,将不胜感激。谢谢
【问题讨论】:
标签: angularjs unit-testing jasmine