Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何使用多个参数调用toHaveBeenCalledWith?_Angularjs_Unit Testing_Jasmine - Fatal编程技术网

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"]);