11import { MatSnackBar } from '@angular/material/snack-bar' ;
22import { createServiceFactory , mockProvider , SpectatorService } from '@ngneat/spectator/jest' ;
3- import { of , throwError } from 'rxjs' ;
3+ import { EMPTY , of , throwError } from 'rxjs' ;
44import { NotificationComponent , NotificationMode } from './notification.component' ;
55import { NotificationService } from './notification.service' ;
66
@@ -87,10 +87,11 @@ describe('NotificationService', () => {
8787
8888 test ( 'withNotification operator should work correctly' , ( ) => {
8989 spectator = createService ( ) ;
90+ const matSnackBar = spectator . inject ( MatSnackBar ) ;
9091
9192 of ( true ) . pipe ( spectator . service . withNotification ( 'success' , 'failure' ) ) . subscribe ( ) ;
9293
93- expect ( spectator . inject ( MatSnackBar ) . openFromComponent ) . toHaveBeenLastCalledWith (
94+ expect ( matSnackBar . openFromComponent ) . toHaveBeenLastCalledWith (
9495 NotificationComponent ,
9596 expect . objectContaining ( {
9697 horizontalPosition : 'left' ,
@@ -102,7 +103,7 @@ describe('NotificationService', () => {
102103
103104 throwError ( 'error' ) . pipe ( spectator . service . withNotification ( 'success' , 'failure' ) ) . subscribe ( ) ;
104105
105- expect ( spectator . inject ( MatSnackBar ) . openFromComponent ) . toHaveBeenLastCalledWith (
106+ expect ( matSnackBar . openFromComponent ) . toHaveBeenLastCalledWith (
106107 NotificationComponent ,
107108 expect . objectContaining ( {
108109 horizontalPosition : 'left' ,
@@ -111,5 +112,10 @@ describe('NotificationService', () => {
111112 data : expect . objectContaining ( { message : 'failure' , mode : NotificationMode . Failure } )
112113 } )
113114 ) ;
115+
116+ // Completing the source observable without emitting a value should not show any message
117+ matSnackBar . openFromComponent . mockClear ( ) ;
118+ EMPTY . pipe ( spectator . service . withNotification ( 'success' , 'failure' ) ) . subscribe ( ) ;
119+ expect ( matSnackBar . openFromComponent ) . not . toHaveBeenCalled ( ) ;
114120 } ) ;
115121} ) ;
0 commit comments