Tried to fix the automatically generated test for HeroDetailComponent
[examples/angular-tour-of-heroes] / src / app / hero-detail / hero-detail.component.spec.ts
1 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2
3 import { HeroDetailComponent } from './hero-detail.component';
4
5 import { Observable, of } from 'rxjs';
6 import { Hero } from '../hero';
7 import { HeroService } from '../hero.service';
8 import {ActivatedRoute } from '@angular/router';
9
10 class MockHeroService {
11
12   getHero(id: number): Observable<Hero> {
13     return of({ id: 666, name: 'Mister Devil' });
14   }
15 }
16
17 class MockLocation {}
18
19 describe('HeroDetailComponent', () => {
20   let component: HeroDetailComponent;
21   let fixture: ComponentFixture<HeroDetailComponent>;
22
23   beforeEach(async(() => {
24     TestBed.configureTestingModule({
25       declarations: [ HeroDetailComponent ],
26       providers: [
27         { provide: ActivatedRoute, useValue: {
28             params: of({ id: '666'})
29           }
30         },
31         { provide: HeroService, useClass: MockHeroService },
32         { provide: Location, useClass: MockLocation }
33       ]
34     })
35     .compileComponents();
36   }));
37
38   beforeEach(() => {
39     fixture = TestBed.createComponent(HeroDetailComponent);
40     component = fixture.componentInstance;
41     fixture.detectChanges();
42   });
43
44   it('should create', () => {
45     expect(component).toBeTruthy();
46   });
47 });