Angularjs 如何使用多个参数调用toHaveBeenCalledWith?
您好,我正在Angularjs 如何使用多个参数调用toHaveBeenCalledWith?,angularjs,unit-testing,jasmine,Angularjs,Unit Testing,Jasmine,您好,我正在Angular JS中开发web应用程序。我正在使用Jasmine框架编写单元测试用例。我试图模仿一些服务。我无法使用多个参数调用服务。下面是我的单元测试代码 it('update is allowed false', async(() => { let service = fixture.debugElement.injector.get(UserOnboardEndpointMock); spyOn(service, 'updateUser'
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);
}
有人能帮我打电话给我的模拟服务吗?任何帮助都将不胜感激。谢谢你自从jest 23.0以来,就有了。与(n调用,arg1,arg2,…)一起调用的 因此,您可以做出如下断言:
expect(service.updateUser).tohaven被调用为带有(1,true,“101”)代码>
expect(service.updateUser).toHaveBeenCalledWith(true,"101");
expect(service.updateUser).toHaveBeenCalledWith([true]["101"]);