Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {ApplicationRef, Component} from '@angular/core';
import {TestBed, inject} from '@angular/core/testing';
import {ApplicationRef, Component, afterRender} from '@angular/core';
import {filter, take} from 'rxjs/operators';
import {ComponentPortal} from '../../portal';
import {dispatchFakeEvent, dispatchMouseEvent} from '../../testing/private';
import {OverlayModule, Overlay} from '../index';
import {Overlay, OverlayModule} from '../index';
import {OverlayOutsideClickDispatcher} from './overlay-outside-click-dispatcher';
import {ComponentPortal} from '../../portal';
import {filter, take} from 'rxjs/operators';

describe('OverlayOutsideClickDispatcher', () => {
let appRef: ApplicationRef;
Expand Down Expand Up @@ -388,11 +388,13 @@ describe('OverlayOutsideClickDispatcher', () => {

it('should run change detection if the click was made outside the overlay and there are `outsidePointerEvents` observers', async () => {
let renders = 0;
TestBed.runInInjectionContext(() => {
afterRender(() => {
@Component({template: '{{increment()}}'})
class Counter {
increment() {
renders++;
});
});
}
}
TestBed.createComponent(Counter);
function stablePromise() {
return TestBed.inject(ApplicationRef)
.isStable.pipe(
Expand All @@ -402,7 +404,8 @@ describe('OverlayOutsideClickDispatcher', () => {
.toPromise();
}
await stablePromise();
expect(renders).toEqual(1);
renders = 0;
expect(renders).toEqual(0);
const portal = new ComponentPortal(TestComponent);
const overlayRef = overlay.create();
overlayRef.attach(portal);
Expand All @@ -412,16 +415,16 @@ describe('OverlayOutsideClickDispatcher', () => {
document.body.appendChild(context);

await stablePromise();
expect(renders).toEqual(2);
expect(renders).toEqual(1);
dispatchMouseEvent(context, 'click');
await stablePromise();
expect(renders).toEqual(2);
expect(renders).toEqual(1);

overlayRef.outsidePointerEvents().subscribe();

dispatchMouseEvent(context, 'click');
await stablePromise();
expect(renders).toEqual(2);
expect(renders).toEqual(1);
});
});
});
Expand Down
Loading