@@ -9,7 +9,7 @@ import { RouteService } from './route.service';
99import { RouterMock } from '../../shared/mocks/router.mock' ;
1010import { TestScheduler } from 'rxjs/testing' ;
1111import { AddUrlToHistoryAction } from '../history/history.actions' ;
12- import { NativeWindowRef , NativeWindowService } from './window.service ' ;
12+ import { NativeWindowRefMock } from '../../shared/mocks/mock-native-window-ref ' ;
1313
1414describe ( 'RouteService' , ( ) => {
1515 let scheduler : TestScheduler ;
@@ -49,18 +49,19 @@ describe('RouteService', () => {
4949 } ,
5050 { provide : Router , useValue : router } ,
5151 { provide : Store , useValue : store } ,
52- { provide : NativeWindowService , useClass : new NativeWindowRef ( ) } ,
52+ { provide : NativeWindowRefMock , useClass : NativeWindowRefMock }
5353 ]
5454 } ) ;
5555 } ) ) ;
5656
5757 beforeEach ( ( ) => {
58- service = new RouteService ( TestBed . inject ( ActivatedRoute ) , TestBed . inject ( Router ) , TestBed . inject ( Store ) , TestBed . inject ( NativeWindowRef ) ) ;
58+ service = new RouteService ( TestBed . inject ( ActivatedRoute ) , TestBed . inject ( Router ) , TestBed . inject ( Store ) , TestBed . inject ( NativeWindowRefMock ) ) ;
5959 serviceAsAny = service ;
6060 } ) ;
6161
6262 describe ( 'hasQueryParam' , ( ) => {
6363 it ( 'should return true when the parameter name exists' , ( ) => {
64+ spyOnProperty ( serviceAsAny . _window . nativeWindow . location , 'href' ) . and . returnValue ( 'http://localhost?name=Test%20Name' ) ;
6465 service . hasQueryParam ( paramName1 ) . subscribe ( ( status ) => {
6566 expect ( status ) . toBeTruthy ( ) ;
6667 } ) ;
@@ -74,6 +75,7 @@ describe('RouteService', () => {
7475
7576 describe ( 'hasQueryParamWithValue' , ( ) => {
7677 it ( 'should return true when the parameter name exists and contains the specified value' , ( ) => {
78+ spyOnProperty ( serviceAsAny . _window . nativeWindow . location , 'href' ) . and . returnValue ( 'http://localhost?name=Test%20Name' ) ;
7779 service . hasQueryParamWithValue ( paramName2 , paramValue2a ) . subscribe ( ( status ) => {
7880 expect ( status ) . toBeTruthy ( ) ;
7981 } ) ;
@@ -92,6 +94,7 @@ describe('RouteService', () => {
9294
9395 describe ( 'getQueryParameterValues' , ( ) => {
9496 it ( 'should return a list of values when the parameter exists' , ( ) => {
97+ spyOnProperty ( serviceAsAny . _window . nativeWindow . location , 'href' ) . and . returnValue ( 'http://localhost?id=Test%20id&another=another%20id' ) ;
9598 service . getQueryParameterValues ( paramName2 ) . subscribe ( ( params ) => {
9699 expect ( params ) . toEqual ( [ paramValue2a , paramValue2b ] ) ;
97100 } ) ;
@@ -106,12 +109,14 @@ describe('RouteService', () => {
106109
107110 describe ( 'getQueryParameterValue' , ( ) => {
108111 it ( 'should return a single value when the parameter exists' , ( ) => {
112+ spyOnProperty ( serviceAsAny . _window . nativeWindow . location , 'href' ) . and . returnValue ( 'http://localhost?name=Test%20Name' ) ;
109113 service . getQueryParameterValue ( paramName1 ) . subscribe ( ( params ) => {
110114 expect ( params ) . toEqual ( paramValue1 ) ;
111115 } ) ;
112116 } ) ;
113117
114118 it ( 'should return only the first value when the parameter exists' , ( ) => {
119+ spyOnProperty ( serviceAsAny . _window . nativeWindow . location , 'href' ) . and . returnValue ( 'http://localhost?id=Test%id' ) ;
115120 service . getQueryParameterValue ( paramName2 ) . subscribe ( ( params ) => {
116121 expect ( params ) . toEqual ( paramValue2a ) ;
117122 } ) ;
0 commit comments