简体   繁体   English

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

[英]Unit test NG2 service call that uses .map()

I have the following function in a service - 我在服务中具有以下功能-

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

In my component I call this function to make the API call - Everything is fine at this point 在我的组件中,我调用此函数进行API调用-此时一切都很好

When I come to test it, I have the following so far - 来进行测试时,到目前为止,我有以下内容-

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

    expect( service.get() ).toBeTruthy();
} ) );

This passes, however I need to test the .map() - Can someone point me in the right direction on how to do this? 这通过了,但是我需要测试.map()-有人可以指出正确的方向吗?

Turns out I was going about this the wrong way. 原来我是用错误的方式来做的。

I was mocking the Http module myself - Queue MockBackend 我自己在嘲笑Http模块-队列MockBackend

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM