|
1 |
| -import {TestBed, inject} from '@angular/core/testing'; |
| 1 | +import {TestBed, inject, fakeAsync} from '@angular/core/testing'; |
2 | 2 | import {Component, NgModule} from '@angular/core';
|
3 | 3 | import {OverlayModule, OverlayContainer, Overlay} from '../index';
|
4 | 4 | import {OverlayOutsideClickDispatcher} from './overlay-outside-click-dispatcher';
|
@@ -155,6 +155,40 @@ describe('OverlayOutsideClickDispatcher', () => {
|
155 | 155 |
|
156 | 156 | overlayRef.dispose();
|
157 | 157 | });
|
| 158 | + |
| 159 | + it( |
| 160 | + 'should not throw an error when when closing out related components via the' + |
| 161 | + ' outsidePointerEvents emitter on background click', |
| 162 | + () => { |
| 163 | + const firstOverlayRef = overlay.create(); |
| 164 | + firstOverlayRef.attach(new ComponentPortal(TestComponent)); |
| 165 | + const secondOverlayRef = overlay.create(); |
| 166 | + secondOverlayRef.attach(new ComponentPortal(TestComponent)); |
| 167 | + const thirdOverlayRef = overlay.create(); |
| 168 | + thirdOverlayRef.attach(new ComponentPortal(TestComponent)); |
| 169 | + |
| 170 | + const spy = jasmine.createSpy('background click handler spy').and.callFake(() => { |
| 171 | + // we close out both overlays from a single outside click event |
| 172 | + firstOverlayRef.detach(); |
| 173 | + thirdOverlayRef.detach(); |
| 174 | + }); |
| 175 | + firstOverlayRef.outsidePointerEvents().subscribe(spy); |
| 176 | + secondOverlayRef.outsidePointerEvents().subscribe(spy); |
| 177 | + thirdOverlayRef.outsidePointerEvents().subscribe(spy); |
| 178 | + |
| 179 | + const backgroundElement = document.createElement('div'); |
| 180 | + document.body.appendChild(backgroundElement); |
| 181 | + |
| 182 | + expect(fakeAsync(() => backgroundElement.click())).not.toThrowError(); |
| 183 | + |
| 184 | + expect(spy).toHaveBeenCalled(); |
| 185 | + |
| 186 | + backgroundElement.parentNode!.removeChild(backgroundElement); |
| 187 | + firstOverlayRef.dispose(); |
| 188 | + secondOverlayRef.dispose(); |
| 189 | + thirdOverlayRef.dispose(); |
| 190 | + } |
| 191 | + ); |
158 | 192 | });
|
159 | 193 |
|
160 | 194 |
|
|
0 commit comments