@@ -56,7 +56,13 @@ describe('uiSref', () => {
5656 } ;
5757
5858 // Extract the logical portion of the URL after the hash
59- const urlOfElement = ( srefElement : DebugElement ) => srefElement . nativeElement . href . replace ( / ^ [ ^ # ] * # / , '' ) ;
59+ const urlOfElement = ( srefElement : DebugElement ) => {
60+ let href = srefElement . nativeElement . href ;
61+ if ( typeof location === 'object' && href . startsWith ( location . href ) ) {
62+ href = href . substr ( location . href . length ) ;
63+ }
64+ return href . replace ( / ^ [ ^ # ] * # / , '' ) ;
65+ } ;
6066
6167 it ( 'renders an href for a state with an url' , ( ) => {
6268 const { fixture, srefElements, router } = setup ( ) ;
@@ -67,14 +73,14 @@ describe('uiSref', () => {
6773 expect ( urlOfElement ( srefElements [ 0 ] ) ) . toBe ( '/myurl' ) ;
6874 } ) ;
6975
70- // it('renders an empty href for a url-less state', () => {
71- // const { fixture, srefElements, router } = setup();
72- // router.stateRegistry.register({ name: 'urlless' });
73- // fixture.componentInstance.linkA = 'urlless';
74- // fixture.detectChanges();
75- // expect(srefElements[0].nativeElement.hasAttribute('href')).toBeTruthy();
76- // expect(urlOfElement(srefElements[0])).toBe('');
77- // });
76+ it ( 'renders an empty href for a url-less state' , ( ) => {
77+ const { fixture, srefElements, router } = setup ( ) ;
78+ router . stateRegistry . register ( { name : 'urlless' } ) ;
79+ fixture . componentInstance . linkA = 'urlless' ;
80+ fixture . detectChanges ( ) ;
81+ expect ( srefElements [ 0 ] . nativeElement . hasAttribute ( 'href' ) ) . toBeTruthy ( ) ;
82+ expect ( urlOfElement ( srefElements [ 0 ] ) ) . toBe ( '' ) ;
83+ } ) ;
7884
7985 it ( 'renders no href when the sref state is empty' , ( ) => {
8086 const { fixture, srefElements } = setup ( ) ;
0 commit comments