From b52b79a39e71932d1413cfbeca4d4ae3a50fe35b Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 16 May 2020 12:42:55 +0200 Subject: [PATCH] 6: Get Data from a Server d) Heroes and HTTP - Get Heroes with HttpClient (Fixed Tests) --- src/app/dashboard/dashboard.component.spec.ts | 7 ++++++- src/app/hero.service.spec.ts | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/dashboard/dashboard.component.spec.ts b/src/app/dashboard/dashboard.component.spec.ts index 9c996c3..bfadb09 100644 --- a/src/app/dashboard/dashboard.component.spec.ts +++ b/src/app/dashboard/dashboard.component.spec.ts @@ -1,6 +1,8 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { DashboardComponent } from './dashboard.component'; +import { HeroService } from '../hero.service'; +import { of } from 'rxjs'; describe('DashboardComponent', () => { let component: DashboardComponent; @@ -8,7 +10,10 @@ describe('DashboardComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ DashboardComponent ] + declarations: [ DashboardComponent ], + providers: [ + { provide: HeroService, useValue: { getHeroes: () => of([])}} + ] }) .compileComponents(); })); diff --git a/src/app/hero.service.spec.ts b/src/app/hero.service.spec.ts index 0ec21de..de1c518 100644 --- a/src/app/hero.service.spec.ts +++ b/src/app/hero.service.spec.ts @@ -2,15 +2,16 @@ import { TestBed} from '@angular/core/testing'; import { TestScheduler } from 'rxjs/testing'; import { HeroService } from './hero.service'; -import { Hero } from './hero'; -import {map} from 'rxjs/operators'; +import { HttpClientTestingModule } from '@angular/common/http/testing'; describe('HeroService', () => { let service: HeroService; let scheduler: TestScheduler; beforeEach(() => { - TestBed.configureTestingModule({}); + TestBed.configureTestingModule({ + imports: [ HttpClientTestingModule ] + }); service = TestBed.inject(HeroService); scheduler = new TestScheduler(((actual, expected) => { expect(actual).toEqual(expected); -- 2.20.1