簡體   English   中英

使用.map()的單元測試NG2服務調用

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

我在服務中具有以下功能-

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模塊-隊列MockBackend

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM