@@ -124,6 +124,37 @@ describe('LocationService', () => {
124124 } ) ;
125125 } ) ;
126126
127+ describe ( 'path' , ( ) => {
128+ it ( 'should ask Location for the current path without the hash' , ( ) => {
129+ const location : MockLocationStrategy = injector . get ( LocationStrategy ) ;
130+ const service : LocationService = injector . get ( LocationService ) ;
131+
132+ // We cannot test this directly in the following test because the `MockLocationStrategy`
133+ // does not remove the hash from the path, even if we do pass `false`.
134+
135+ spyOn ( location , 'path' ) . and . callThrough ( ) ;
136+ service . path ( ) ;
137+ expect ( location . path ) . toHaveBeenCalledWith ( false ) ;
138+ } ) ;
139+
140+ it ( 'should return the current location.path, with the query and trailing slash stripped off' , ( ) => {
141+ const location : MockLocationStrategy = injector . get ( LocationStrategy ) ;
142+ const service : LocationService = injector . get ( LocationService ) ;
143+
144+ location . simulatePopState ( 'a/b/c?foo=bar&moo=car' ) ;
145+ expect ( service . path ( ) ) . toEqual ( 'a/b/c' ) ;
146+
147+ location . simulatePopState ( 'c/d/e' ) ;
148+ expect ( service . path ( ) ) . toEqual ( 'c/d/e' ) ;
149+
150+ location . simulatePopState ( 'a/b/c/?foo=bar&moo=car' ) ;
151+ expect ( service . path ( ) ) . toEqual ( 'a/b/c' ) ;
152+
153+ location . simulatePopState ( 'c/d/e/' ) ;
154+ expect ( service . path ( ) ) . toEqual ( 'c/d/e' ) ;
155+ } ) ;
156+ } ) ;
157+
127158 describe ( 'search' , ( ) => {
128159 it ( 'should read the query from the current location.path' , ( ) => {
129160 const location : MockLocationStrategy = injector . get ( LocationStrategy ) ;
0 commit comments