使用 .map() 的 NG2 服务调用进行单元测试



我在服务中有以下函数-

get(): Observable<any> {
    return this._http.get( 'endpoint', {}, false )
        .map( this.getJson );
}

在我的组件中,我调用此函数进行 API 调用 - 此时一切都很好

当我来测试它时,到目前为止我有以下内容-

it( 'expect service.get() to exist', inject( [ ExampleService ], ( service: ExampleService ) => {
    spyOn(service, 'get').and.callFake(function(){
        return resp;
    });
    expect( service.get() ).toBeTruthy();
} ) );

这通过了,但是我需要测试 .map(( - 有人可以指出我如何做到这一点的正确方向吗?

事实证明,我的做法是错误的。

我自己在模拟 Http 模块 - 队列模拟后端

最新更新