X-Git-Url: https://juplo.de/gitweb/?p=examples%2Fangular-tour-of-heroes;a=blobdiff_plain;f=src%2Fapp%2Fhero-detail%2Fhero-detail.component.spec.ts;h=e2235b495e1eb915b5b27224f0c4bc43746e583c;hp=5e34497bec9c7af8555fcd253a91492875a0784c;hb=d42007487362bd314434f11dc26c3a291e7ff4e7;hpb=f18faff7c576b595dd8765f36805aa8176122db7 diff --git a/src/app/hero-detail/hero-detail.component.spec.ts b/src/app/hero-detail/hero-detail.component.spec.ts index 5e34497..e2235b4 100644 --- a/src/app/hero-detail/hero-detail.component.spec.ts +++ b/src/app/hero-detail/hero-detail.component.spec.ts @@ -2,13 +2,35 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { HeroDetailComponent } from './hero-detail.component'; +import { Observable, of } from 'rxjs'; +import { Hero } from '../hero'; +import { HeroService } from '../hero.service'; +import {ActivatedRoute } from '@angular/router'; + +class MockHeroService { + + getHero(id: number): Observable { + return of({ id: 666, name: 'Mister Devil' }); + } +} + +class MockLocation {} + describe('HeroDetailComponent', () => { let component: HeroDetailComponent; let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ HeroDetailComponent ] + declarations: [ HeroDetailComponent ], + providers: [ + { provide: ActivatedRoute, useValue: { + params: of({ id: '666'}) + } + }, + { provide: HeroService, useClass: MockHeroService }, + { provide: Location, useClass: MockLocation } + ] }) .compileComponents(); }));