@@ -1172,6 +1172,50 @@ describe('MatDialog', () => {
11721172
11731173 overlayContainerElement . remove ( ) ;
11741174 } ) ) ;
1175+
1176+ it ( 'should support async closePredicate that returns a Promise' , fakeAsync ( ( ) => {
1177+ let resolvePromise : ( value : boolean ) => void ;
1178+ const closedSpy = jasmine . createSpy ( 'closed spy' ) ;
1179+ const ref = dialog . open ( PizzaMsg , {
1180+ closePredicate : ( ) =>
1181+ new Promise < boolean > ( resolve => {
1182+ resolvePromise = resolve ;
1183+ } ) ,
1184+ viewContainerRef : testViewContainerRef ,
1185+ } ) ;
1186+
1187+ ref . afterClosed ( ) . subscribe ( closedSpy ) ;
1188+ viewContainerFixture . detectChanges ( ) ;
1189+
1190+ expect ( getDialogs ( ) . length ) . toBe ( 1 ) ;
1191+
1192+ // Try to close - should not close immediately
1193+ ref . close ( 'test-result' ) ;
1194+ viewContainerFixture . detectChanges ( ) ;
1195+ flush ( ) ;
1196+
1197+ expect ( getDialogs ( ) . length ) . toBe ( 1 ) ;
1198+ expect ( closedSpy ) . not . toHaveBeenCalled ( ) ;
1199+
1200+ // Resolve promise with false - should still not close
1201+ resolvePromise ! ( false ) ;
1202+ tick ( ) ;
1203+ viewContainerFixture . detectChanges ( ) ;
1204+ flush ( ) ;
1205+
1206+ expect ( getDialogs ( ) . length ) . toBe ( 1 ) ;
1207+ expect ( closedSpy ) . not . toHaveBeenCalled ( ) ;
1208+
1209+ // Try to close again and resolve with true - should close
1210+ ref . close ( 'test-result' ) ;
1211+ resolvePromise ! ( true ) ;
1212+ tick ( ) ;
1213+ viewContainerFixture . detectChanges ( ) ;
1214+ flush ( ) ;
1215+
1216+ expect ( getDialogs ( ) . length ) . toBe ( 0 ) ;
1217+ expect ( closedSpy ) . toHaveBeenCalledWith ( 'test-result' ) ;
1218+ } ) ) ;
11751219 } ) ;
11761220
11771221 it (
0 commit comments