How to mock a service which has http requests?
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 25/100
- issue の種類
- ドキュメント
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- typescript
- 領域
- api, testing-qa
調査の方向性
この issue では service.ts と service.spec.ts が挙げられており、getGoogle() が http.get() を呼び出すことに焦点を当てています。まず、リポジトリの Karma と Jasmine のセットアップ、および既存のテスト設定を確認してください。ライブリクエストに依存せずにメソッドをテストする、文書化された再現可能な方法ができれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Hey,
I know this is not the right platform to ask this, but on right platform, there is no reply from anyone.
How to mock a service which contains http requests?
For eg:
I want to test my provider class, so I am unable to write spec for providers.
My provider is as follows:
service.ts
//imports are done correctly.
@Injectable()
export class Service {
constructor(private http: Http) { }
getGoogle():Observable<any> {
console.log("Inside service");
return this.http.get('https://jsonplaceholder.typicode.com/posts/1');
} }
My page.ts is as follows:
page.ts
**//imports are done correctly.
export class Page1 {
constructor(private service: Service, private navCtrl: NavController) { }
async get() { console.log("inside get method");
const data = await this.service.getGoogle().toPromise();
console.log('The response is' , data);
} }
service.spec.ts
//imports are done correctly
describe('Service', () =>
{ let comp: Service;
let fixture: ComponentFixture<Service>;
let de: DebugElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [],
imports: [
IonicModule.forRoot(Service)
],
providers: [Http]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(Service);
comp = fixture.componentInstance;
de = fixture.debugElement;
});
afterEach(() => {
fixture.destroy();
});
it('test the http request to te server', ()=>{
//code to test http request of the Service class });
});**
All the imports are done correctly, only the logic to test the getGoogle() with http.get() needs to be tested.Please help or share some links or tell me some steps in order to do testing of this ionic2 content.
Thanks
Adi
- 主要言語
- TypeScript
- スター
- 370
- フォーク
- 144
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ionic-team/ionic-unit-testing-example のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 20/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 20/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
ionic-team/ionic-unit-testing-example#91 · コメント 7 件 · リアクション 11 件 ·
ionic-team/ionic-unit-testing-example の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
calcite-components needs triage refactor
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Esri/calcite-design-system#15203 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
danielmiessler/LifeOS#2218 ·