Skip to content

Commit

Permalink
test that beforeClose emits before container is destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
willshowell committed Aug 16, 2017
1 parent 39e38da commit c262622
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/lib/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}));
Expand Down

0 comments on commit c262622

Please sign in to comment.