projects
/
examples
/
angular-tour-of-heroes
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
WIP: 6: Get Data from a Server k) Search by name
[examples/angular-tour-of-heroes]
/
src
/
app
/
hero-detail
/
hero-detail.component.spec.ts
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
(file)
--- 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 { 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({
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();
}));
})
.compileComponents();
}));