diff --git a/aio/src/app/app.component.spec.ts b/aio/src/app/app.component.spec.ts index 79549c767f..328501569e 100644 --- a/aio/src/app/app.component.spec.ts +++ b/aio/src/app/app.component.spec.ts @@ -742,7 +742,7 @@ describe('AppComponent', () => { expect(component.showSearchResults).toBe(true); }); - it('should not intercept clicks om the searchBox', () => { + it('should not intercept clicks on the searchBox', () => { component.showSearchResults = true; fixture.detectChanges(); @@ -752,6 +752,11 @@ describe('AppComponent', () => { expect(component.showSearchResults).toBe(true); }); + + it('should not call `locationService.setSearch` when searchResults are not shown', () => { + docViewer.click(); + expect(locationService.setSearch).not.toHaveBeenCalled(); + }); }); describe('keyup handling', () => { diff --git a/aio/src/app/app.component.ts b/aio/src/app/app.component.ts index 820796fb69..65c4855200 100644 --- a/aio/src/app/app.component.ts +++ b/aio/src/app/app.component.ts @@ -389,7 +389,10 @@ export class AppComponent implements OnInit { hideSearchResults() { this.showSearchResults = false; - this.locationService.setSearch('', { ...this.locationService.search(), search: undefined }); + const oldSearch = this.locationService.search(); + if (oldSearch.search !== undefined) { + this.locationService.setSearch('', { ...oldSearch, search: undefined }); + } } focusSearchBox() {