|
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 {dispatchMouseEvent} from '@angular/cdk/testing/private';
|
4 | 4 | import {OverlayModule, OverlayContainer, Overlay} from '../index';
|
@@ -186,6 +186,40 @@ describe('OverlayOutsideClickDispatcher', () => {
|
186 | 186 |
|
187 | 187 | overlayRef.dispose();
|
188 | 188 | });
|
| 189 | + |
| 190 | + it( |
| 191 | + 'should not throw an error when when closing out related components via the' + |
| 192 | + ' outsidePointerEvents emitter on background click', |
| 193 | + fakeAsync(() => { |
| 194 | + const firstOverlayRef = overlay.create(); |
| 195 | + firstOverlayRef.attach(new ComponentPortal(TestComponent)); |
| 196 | + const secondOverlayRef = overlay.create(); |
| 197 | + secondOverlayRef.attach(new ComponentPortal(TestComponent)); |
| 198 | + const thirdOverlayRef = overlay.create(); |
| 199 | + thirdOverlayRef.attach(new ComponentPortal(TestComponent)); |
| 200 | + |
| 201 | + const spy = jasmine.createSpy('background click handler spy').and.callFake(() => { |
| 202 | + // we close out both overlays from a single outside click event |
| 203 | + firstOverlayRef.detach(); |
| 204 | + thirdOverlayRef.detach(); |
| 205 | + }); |
| 206 | + firstOverlayRef.outsidePointerEvents().subscribe(spy); |
| 207 | + secondOverlayRef.outsidePointerEvents().subscribe(spy); |
| 208 | + thirdOverlayRef.outsidePointerEvents().subscribe(spy); |
| 209 | + |
| 210 | + const backgroundElement = document.createElement('div'); |
| 211 | + document.body.appendChild(backgroundElement); |
| 212 | + |
| 213 | + expect(() => backgroundElement.click()).not.toThrowError(); |
| 214 | + |
| 215 | + expect(spy).toHaveBeenCalled(); |
| 216 | + |
| 217 | + backgroundElement.parentNode!.removeChild(backgroundElement); |
| 218 | + firstOverlayRef.dispose(); |
| 219 | + secondOverlayRef.dispose(); |
| 220 | + thirdOverlayRef.dispose(); |
| 221 | + } |
| 222 | + )); |
189 | 223 | });
|
190 | 224 |
|
191 | 225 |
|
|
0 commit comments