|
6 | 6 | * found in the LICENSE file at https://angular.io/license |
7 | 7 | */ |
8 | 8 |
|
9 | | -import {APP_BASE_HREF, DOCUMENT, Location, ɵgetDOM as getDOM} from '@angular/common'; |
| 9 | +import {APP_BASE_HREF, DOCUMENT, ɵgetDOM as getDOM} from '@angular/common'; |
10 | 10 | import {ApplicationRef, Component, CUSTOM_ELEMENTS_SCHEMA, destroyPlatform, NgModule} from '@angular/core'; |
11 | 11 | import {inject} from '@angular/core/testing'; |
12 | 12 | import {BrowserModule} from '@angular/platform-browser'; |
13 | 13 | import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; |
14 | 14 | import {NavigationEnd, Resolve, Router, RouterModule} from '@angular/router'; |
15 | | -import {filter, first} from 'rxjs/operators'; |
16 | 15 |
|
17 | 16 | describe('bootstrap', () => { |
18 | 17 | if (isNode) return; |
@@ -369,7 +368,30 @@ describe('bootstrap', () => { |
369 | 368 | done(); |
370 | 369 | }); |
371 | 370 |
|
372 | | - function waitForNavigationToComplete(router: Router): Promise<any> { |
373 | | - return router.events.pipe(filter((e: any) => e instanceof NavigationEnd), first()).toPromise(); |
374 | | - } |
| 371 | + it('should cleanup "popstate" and "hashchange" listeners', async () => { |
| 372 | + @NgModule({ |
| 373 | + imports: [BrowserModule, RouterModule.forRoot([])], |
| 374 | + declarations: [RootCmp], |
| 375 | + bootstrap: [RootCmp], |
| 376 | + providers: testProviders, |
| 377 | + }) |
| 378 | + class TestModule { |
| 379 | + } |
| 380 | + |
| 381 | + spyOn(window, 'addEventListener').and.callThrough(); |
| 382 | + spyOn(window, 'removeEventListener').and.callThrough(); |
| 383 | + |
| 384 | + const ngModuleRef = await platformBrowserDynamic().bootstrapModule(TestModule); |
| 385 | + ngModuleRef.destroy(); |
| 386 | + |
| 387 | + expect(window.addEventListener).toHaveBeenCalledTimes(2); |
| 388 | + |
| 389 | + expect(window.addEventListener) |
| 390 | + .toHaveBeenCalledWith('popstate', jasmine.any(Function), jasmine.any(Boolean)); |
| 391 | + expect(window.addEventListener) |
| 392 | + .toHaveBeenCalledWith('hashchange', jasmine.any(Function), jasmine.any(Boolean)); |
| 393 | + |
| 394 | + expect(window.removeEventListener).toHaveBeenCalledWith('popstate', jasmine.any(Function)); |
| 395 | + expect(window.removeEventListener).toHaveBeenCalledWith('hashchange', jasmine.any(Function)); |
| 396 | + }); |
375 | 397 | }); |
0 commit comments