実際のバックエンドでhttp注入を使用してジャスミンテストを実現するにはどうすればよいですか?実際の接続でHTTPをジャスミンに注入する方法
私は本当のhttp接続
import { provide } from '@angular/core';
import{ClassCall} from 'xx.xx'
import {HTTP_PROVIDERS, XHRBackend, Http} from "@angular/http";
import {MockBackend} from "@angular/http/testing/mock_backend";
import {beforeEachProviders} from "@angular/core/testing/testing";
import {inject} from "@angular/core/testing/test_injector";
import {async} from "@angular/core/testing/async";
describe('HttpService Tests',() => {
beforeEachProviders(() => {
return [
HTTP_PROVIDERS,
Http,
ClassCall,
provide(ClassCall, {useClass: Http}),
];
})
it('should return response when subscribed to postRequest',
async(inject([ClassCall], (myCall: ClassCall) => {
myCall.Call("hey", "there")
.then((response)=>{
expect(response).toBe("anyResponse")
})
})));
});
を使用して、私のサービスをテストしたいことを意味し、私はそれについてのトピックを見ていない....
感謝を!!!!!
お返事ありがとうございます。しかし、私はIonic 2を使用しているので、角度2.0.0.0rc4にロックされています... あなたのアドバイスに基づいてコードを変更しようとしました。 しかし、それはまだ動作しません.... 私はエラーが発生しました: 'AuthServiceのプロバイダなし... 注入がうまくいかないようです – charlesg
あなたのonewクラスを置く必要がありますAuthServiceは私のサービスからの私の例です); – igorzg
私の応答に示されているように動作していない – charlesg