@@ -9,6 +9,8 @@ import {TestsModule} from '../../../shared/modules/tests.module';
99import { Error404Page } from '../../pages/error404/error404.page' ;
1010import { HomePage } from '../../pages/home/home.page' ;
1111import { HeroService } from '../../../modules/heroes/shared/hero.service' ;
12+ import { Router } from '@angular/router' ;
13+ import { Hero } from '../../../modules/heroes/shared/hero.model' ;
1214
1315describe ( 'HeroSearchComponent' , ( ) => {
1416 let fixture ;
@@ -28,6 +30,12 @@ describe('HeroSearchComponent', () => {
2830 Error404Page
2931 ] ,
3032 providers : [
33+ {
34+ provide : Router ,
35+ useClass : class {
36+ navigate = jasmine . createSpy ( 'navigate' ) ;
37+ }
38+ } ,
3139 { provide : APP_CONFIG , useValue : AppConfig } ,
3240 { provide : APP_BASE_HREF , useValue : '/' } ,
3341 HeroService
@@ -72,4 +80,10 @@ describe('HeroSearchComponent', () => {
7280 expect ( component . filterHeroes ( 'spiderman' ) . length ) . toBe ( 0 ) ;
7381 expect ( component . filterHeroes ( ) . length ) . toBe ( 2 ) ;
7482 } ) ) ;
83+
84+ it ( 'should navigate to hero detail' , ( ( ) => {
85+ const router = fixture . debugElement . injector . get ( Router ) ;
86+ component . searchHero ( new Hero ( 5 , 'test name' , 'test alterEgo' , 0 ) ) ;
87+ expect ( router . navigate ) . toHaveBeenCalledWith ( [ 'heroes/5' ] ) ;
88+ } ) ) ;
7589} ) ;
0 commit comments