From c262622b756044c5a205eb0a128c78c941a9b5ba Mon Sep 17 00:00:00 2001 From: Will Howell Date: Wed, 16 Aug 2017 17:11:42 -0400 Subject: [PATCH] test that beforeClose emits before container is destroyed --- src/lib/dialog/dialog.spec.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib/dialog/dialog.spec.ts b/src/lib/dialog/dialog.spec.ts index ccc7368fb777..5bbcea4974ea 100644 --- a/src/lib/dialog/dialog.spec.ts +++ b/src/lib/dialog/dialog.spec.ts @@ -141,15 +141,20 @@ describe('MdDialog', () => { })); it('should close a dialog and get back a result before it is closed', async(() => { - let dialogRef = dialog.open(PizzaMsg, { viewContainerRef: testViewContainerRef }); - let beforeCloseCallback = jasmine.createSpy('beforeClose callback'); + const dialogRef = dialog.open(PizzaMsg, { viewContainerRef: testViewContainerRef }); + + // beforeClose should emit before dialog container is destroyed + const beforeCloseHandler = jasmine.createSpy('beforeClose callback').and.callFake(() => { + expect(overlayContainerElement.querySelector('md-dialog-container')) + .not.toBeNull('dialog container exists when beforeClose is called'); + }); - dialogRef.beforeClose().subscribe(beforeCloseCallback); + dialogRef.beforeClose().subscribe(beforeCloseHandler); dialogRef.close('Bulbasaurus'); viewContainerFixture.detectChanges(); viewContainerFixture.whenStable().then(() => { - expect(beforeCloseCallback).toHaveBeenCalledWith('Bulbasaurus'); + expect(beforeCloseHandler).toHaveBeenCalledWith('Bulbasaurus'); expect(overlayContainerElement.querySelector('md-dialog-container')).toBeNull(); }); }));