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<Hero> {
+ return of({ id: 666, name: 'Mister Devil' });
+ }
+}
+
+class MockLocation {}
+
describe('HeroDetailComponent', () => {
let component: HeroDetailComponent;
let fixture: ComponentFixture<HeroDetailComponent>;
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();
}));