@@ -309,13 +309,35 @@ describe('AppComponent', () => {
309309 describe ( 'click intercepting' , ( ) => {
310310 it ( 'should intercept clicks on anchors and call `location.handleAnchorClick()`' ,
311311 inject ( [ LocationService ] , ( location : LocationService ) => {
312- const anchorElement : HTMLAnchorElement = document . createElement ( 'a' ) ;
313- anchorElement . href = 'some/local/url' ;
314- fixture . nativeElement . append ( anchorElement ) ;
312+
313+ const el = fixture . nativeElement as Element ;
314+ el . innerHTML = '<a href="some/local/url">click me</a>' ;
315+ const anchorElement = el . getElementsByTagName ( 'a' ) [ 0 ] ;
315316 anchorElement . click ( ) ;
316317 expect ( location . handleAnchorClick ) . toHaveBeenCalledWith ( anchorElement , 0 , false , false ) ;
317318 } ) ) ;
318319
320+ it ( 'should intercept clicks on elements deep within an anchor tag' ,
321+ inject ( [ LocationService ] , ( location : LocationService ) => {
322+
323+ const el = fixture . nativeElement as Element ;
324+ el . innerHTML = '<a href="some/local/url"><div><img></div></a>' ;
325+ const imageElement = el . getElementsByTagName ( 'img' ) [ 0 ] ;
326+ const anchorElement = el . getElementsByTagName ( 'a' ) [ 0 ] ;
327+ imageElement . click ( ) ;
328+ expect ( location . handleAnchorClick ) . toHaveBeenCalledWith ( anchorElement , 0 , false , false ) ;
329+ } ) ) ;
330+
331+ it ( 'should ignore clicks on elements without an anchor ancestor' ,
332+ inject ( [ LocationService ] , ( location : LocationService ) => {
333+
334+ const el = fixture . nativeElement as Element ;
335+ el . innerHTML = '<div><p><div><img></div></p></div>' ;
336+ const imageElement = el . getElementsByTagName ( 'img' ) [ 0 ] ;
337+ imageElement . click ( ) ;
338+ expect ( location . handleAnchorClick ) . not . toHaveBeenCalled ( ) ;
339+ } ) ) ;
340+
319341 it ( 'should intercept clicks not on the search elements and hide the search results' , ( ) => {
320342 const searchResults : SearchResultsComponent = fixture . debugElement . query ( By . directive ( SearchResultsComponent ) ) . componentInstance ;
321343 spyOn ( searchResults , 'hideResults' ) ;
0 commit comments