|
1 | | -import {waitForAsync, fakeAsync, tick, ComponentFixture, TestBed} from '@angular/core/testing'; |
| 1 | +import { |
| 2 | + waitForAsync, |
| 3 | + fakeAsync, |
| 4 | + tick, |
| 5 | + ComponentFixture, |
| 6 | + TestBed, |
| 7 | + flush, |
| 8 | +} from '@angular/core/testing'; |
2 | 9 | import { |
3 | 10 | Component, |
4 | 11 | ViewChild, |
@@ -463,6 +470,36 @@ describe('Overlay', () => { |
463 | 470 | expect(() => overlayRef.removePanelClass([''])).not.toThrow(); |
464 | 471 | }); |
465 | 472 |
|
| 473 | + it('should detach a component-based overlay when the view is destroyed', fakeAsync(() => { |
| 474 | + const overlayRef = overlay.create(); |
| 475 | + const paneElement = overlayRef.overlayElement; |
| 476 | + |
| 477 | + overlayRef.attach(componentPortal); |
| 478 | + viewContainerFixture.detectChanges(); |
| 479 | + |
| 480 | + expect(paneElement.childNodes.length).not.toBe(0); |
| 481 | + |
| 482 | + viewContainerFixture.destroy(); |
| 483 | + flush(); |
| 484 | + |
| 485 | + expect(paneElement.childNodes.length).toBe(0); |
| 486 | + })); |
| 487 | + |
| 488 | + it('should detach a template-based overlay when the view is destroyed', fakeAsync(() => { |
| 489 | + const overlayRef = overlay.create(); |
| 490 | + const paneElement = overlayRef.overlayElement; |
| 491 | + |
| 492 | + overlayRef.attach(templatePortal); |
| 493 | + viewContainerFixture.detectChanges(); |
| 494 | + |
| 495 | + expect(paneElement.childNodes.length).not.toBe(0); |
| 496 | + |
| 497 | + viewContainerFixture.destroy(); |
| 498 | + flush(); |
| 499 | + |
| 500 | + expect(paneElement.childNodes.length).toBe(0); |
| 501 | + })); |
| 502 | + |
466 | 503 | describe('positioning', () => { |
467 | 504 | let config: OverlayConfig; |
468 | 505 |
|
|
0 commit comments