如何使用多个参数调用toHaveBeenCalledWith函数?

4

你好,我正在开发一个使用 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"]);

有人能帮我调用模拟服务吗?非常感谢您的帮助。谢谢

1个回答

6

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接