简体   繁体   中英

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

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?

Turns out I was going about this the wrong way.

I was mocking the Http module myself - Queue MockBackend

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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