diff --git a/src/cdk-experimental/dialog/dialog.spec.ts b/src/cdk-experimental/dialog/dialog.spec.ts index 0d35e48f690..bc8fbf72603 100644 --- a/src/cdk-experimental/dialog/dialog.spec.ts +++ b/src/cdk-experimental/dialog/dialog.spec.ts @@ -696,7 +696,7 @@ describe('Dialog', () => { }); describe('disableClose option', () => { - it('should prevent closing via clicks on the backdrop', () => { + it('should prevent closing via clicks on the backdrop', fakeAsync(() => { dialog.openFromComponent(PizzaMsg, { disableClose: true, viewContainerRef: testViewContainerRef @@ -706,11 +706,13 @@ describe('Dialog', () => { let backdrop = overlayContainerElement.querySelector('.cdk-overlay-backdrop') as HTMLElement; backdrop.click(); + viewContainerFixture.detectChanges(); + flush(); expect(overlayContainerElement.querySelector('cdk-dialog-container')).toBeTruthy(); - }); + })); - it('should prevent closing via the escape key', () => { + it('should prevent closing via the escape key', fakeAsync(() => { dialog.openFromComponent(PizzaMsg, { disableClose: true, viewContainerRef: testViewContainerRef @@ -718,9 +720,11 @@ describe('Dialog', () => { viewContainerFixture.detectChanges(); dispatchKeyboardEvent(document.body, 'keydown', ESCAPE); + viewContainerFixture.detectChanges(); + flush(); expect(overlayContainerElement.querySelector('cdk-dialog-container')).toBeTruthy(); - }); + })); it('should allow for the disableClose option to be updated while open', fakeAsync(() => { let dialogRef = dialog.openFromComponent(PizzaMsg, { diff --git a/src/cdk-experimental/dialog/dialog.ts b/src/cdk-experimental/dialog/dialog.ts index 1699f2caba8..2207c64eb54 100644 --- a/src/cdk-experimental/dialog/dialog.ts +++ b/src/cdk-experimental/dialog/dialog.ts @@ -225,11 +225,12 @@ export class Dialog implements OnDestroy { // Create a reference to the dialog we're creating in order to give the user a handle // to modify and close it. const dialogRef = new this.dialogRefConstructor(overlayRef, dialogContainer, config.id); - const injector = this._createInjector(config, dialogRef, dialogContainer); const contentRef = dialogContainer.attachComponentPortal( new ComponentPortal(componentOrTemplateRef, undefined, injector)); + dialogRef.componentInstance = contentRef.instance; + dialogRef.disableClose = config.disableClose; dialogRef.updateSize({width: config.width, height: config.height}) .updatePosition(config.position); diff --git a/src/lib/bottom-sheet/bottom-sheet.spec.ts b/src/lib/bottom-sheet/bottom-sheet.spec.ts index a699caaa26e..9abb25750a3 100644 --- a/src/lib/bottom-sheet/bottom-sheet.spec.ts +++ b/src/lib/bottom-sheet/bottom-sheet.spec.ts @@ -429,7 +429,7 @@ describe('MatBottomSheet', () => { }); describe('disableClose option', () => { - it('should prevent closing via clicks on the backdrop', () => { + it('should prevent closing via clicks on the backdrop', fakeAsync(() => { bottomSheet.open(PizzaMsg, { disableClose: true, viewContainerRef: testViewContainerRef @@ -439,11 +439,13 @@ describe('MatBottomSheet', () => { let backdrop = overlayContainerElement.querySelector('.cdk-overlay-backdrop') as HTMLElement; backdrop.click(); + viewContainerFixture.detectChanges(); + flush(); expect(overlayContainerElement.querySelector('mat-bottom-sheet-container')).toBeTruthy(); - }); + })); - it('should prevent closing via the escape key', () => { + it('should prevent closing via the escape key', fakeAsync(() => { bottomSheet.open(PizzaMsg, { disableClose: true, viewContainerRef: testViewContainerRef @@ -451,9 +453,11 @@ describe('MatBottomSheet', () => { viewContainerFixture.detectChanges(); dispatchKeyboardEvent(document.body, 'keydown', ESCAPE); + viewContainerFixture.detectChanges(); + flush(); expect(overlayContainerElement.querySelector('mat-bottom-sheet-container')).toBeTruthy(); - }); + })); }); diff --git a/src/lib/dialog/dialog.spec.ts b/src/lib/dialog/dialog.spec.ts index 385469bbd07..0fd03cdeeb5 100644 --- a/src/lib/dialog/dialog.spec.ts +++ b/src/lib/dialog/dialog.spec.ts @@ -814,7 +814,7 @@ describe('MatDialog', () => { })); describe('disableClose option', () => { - it('should prevent closing via clicks on the backdrop', () => { + it('should prevent closing via clicks on the backdrop', fakeAsync(() => { dialog.open(PizzaMsg, { disableClose: true, viewContainerRef: testViewContainerRef @@ -824,11 +824,13 @@ describe('MatDialog', () => { let backdrop = overlayContainerElement.querySelector('.cdk-overlay-backdrop') as HTMLElement; backdrop.click(); + viewContainerFixture.detectChanges(); + flush(); expect(overlayContainerElement.querySelector('mat-dialog-container')).toBeTruthy(); - }); + })); - it('should prevent closing via the escape key', () => { + it('should prevent closing via the escape key', fakeAsync(() => { dialog.open(PizzaMsg, { disableClose: true, viewContainerRef: testViewContainerRef @@ -836,9 +838,11 @@ describe('MatDialog', () => { viewContainerFixture.detectChanges(); dispatchKeyboardEvent(document.body, 'keydown', ESCAPE); + viewContainerFixture.detectChanges(); + flush(); expect(overlayContainerElement.querySelector('mat-dialog-container')).toBeTruthy(); - }); + })); it('should allow for the disableClose option to be updated while open', fakeAsync(() => { let dialogRef = dialog.open(PizzaMsg, {