Last active
March 24, 2019 17:58
-
-
Save manivelarjunan/7a67023415bf72b5c9ddd76a5cdb89d2 to your computer and use it in GitHub Desktop.
Revisions
-
manivelarjunan revised this gist
Dec 29, 2018 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,9 @@ describe('Shared service:', () => { providers: [SharedService], imports: [HttpClientTestingModule] }); // HttpClientTestingModule - Extended interactions between a data service and the HttpClient can be complex // and difficult to mock with spies. // The HttpClientTestingModule can make these testing scenarios more manageable. }); describe(':', () => { -
manivelarjunan created this gist
Dec 29, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ export interface GoogleData { id: number; country: string; zipCode: string; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ import { TestBed } from '@angular/core/testing'; import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; import { SharedService } from './sharedService.service'; describe('Shared service:', () => { beforeEach(() => { TestBed.configureTestingModule({ providers: [SharedService], imports: [HttpClientTestingModule] }); }); describe(':', () => { function setup() { const sharedService = TestBed.get(SharedService); const httpTestingController = TestBed.get(HttpTestingController); return { sharedService, httpTestingController }; } it('should call the google\'s map data', () => { const { sharedService, httpTestingController } = setup(); const mockGoogleMapData = {id: 1, country : 'United states of america', zipcode: '56743'}; sharedService.getGoogleMapData().subscribe(data => { expect(data.mapData).toEqual(mockGoogleMapData); }); const req = httpTestingController.expectOne('https:www.google.com/googleMapData'); expect(req.request.method).toBe('GET'); req.flush({ mapData: mockGoogleMapData }); }); afterEach(() => { const { httpTestingController } = setup(); httpTestingController.verify(); }); }); }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; import { GoogleData } from './googleData'; @Injectable({ providedIn: 'root' }) export class SharedService { constructor(private httpClient: HttpClient) { } public getGoogleMapData(): Observable<GoogleData> { const options = { headers: new HttpHeaders({ 'content-Type': 'application/json', 'Authorization': 'my-auth-token' }) }; return this.httpClient.get<GoogleData>('https:www.google.com/googleMapData', options); } }