diff --git a/aio/src/app/app.component.spec.ts b/aio/src/app/app.component.spec.ts index ff16d977bf..ebeaba3273 100644 --- a/aio/src/app/app.component.spec.ts +++ b/aio/src/app/app.component.spec.ts @@ -308,13 +308,35 @@ describe('AppComponent', () => { describe('click intercepting', () => { it('should intercept clicks on anchors and call `location.handleAnchorClick()`', inject([LocationService], (location: LocationService) => { - const anchorElement: HTMLAnchorElement = document.createElement('a'); - anchorElement.href = 'some/local/url'; - fixture.nativeElement.append(anchorElement); + + const el = fixture.nativeElement as Element; + el.innerHTML = 'click me'; + const anchorElement = el.getElementsByTagName('a')[0]; anchorElement.click(); expect(location.handleAnchorClick).toHaveBeenCalledWith(anchorElement, 0, false, false); })); + it('should intercept clicks on elements deep within an anchor tag', + inject([LocationService], (location: LocationService) => { + + const el = fixture.nativeElement as Element; + el.innerHTML = ''; + const imageElement = el.getElementsByTagName('img')[0]; + const anchorElement = el.getElementsByTagName('a')[0]; + imageElement.click(); + expect(location.handleAnchorClick).toHaveBeenCalledWith(anchorElement, 0, false, false); + })); + + it('should ignore clicks on elements without an anchor ancestor', + inject([LocationService], (location: LocationService) => { + + const el = fixture.nativeElement as Element; + el.innerHTML = '