1
1
import { MatSnackBar } from '@angular/material/snack-bar' ;
2
2
import { createServiceFactory , mockProvider , SpectatorService } from '@ngneat/spectator/jest' ;
3
- import { of , throwError } from 'rxjs' ;
3
+ import { EMPTY , of , throwError } from 'rxjs' ;
4
4
import { NotificationComponent , NotificationMode } from './notification.component' ;
5
5
import { NotificationService } from './notification.service' ;
6
6
@@ -87,10 +87,11 @@ describe('NotificationService', () => {
87
87
88
88
test ( 'withNotification operator should work correctly' , ( ) => {
89
89
spectator = createService ( ) ;
90
+ const matSnackBar = spectator . inject ( MatSnackBar ) ;
90
91
91
92
of ( true ) . pipe ( spectator . service . withNotification ( 'success' , 'failure' ) ) . subscribe ( ) ;
92
93
93
- expect ( spectator . inject ( MatSnackBar ) . openFromComponent ) . toHaveBeenLastCalledWith (
94
+ expect ( matSnackBar . openFromComponent ) . toHaveBeenLastCalledWith (
94
95
NotificationComponent ,
95
96
expect . objectContaining ( {
96
97
horizontalPosition : 'left' ,
@@ -102,7 +103,7 @@ describe('NotificationService', () => {
102
103
103
104
throwError ( 'error' ) . pipe ( spectator . service . withNotification ( 'success' , 'failure' ) ) . subscribe ( ) ;
104
105
105
- expect ( spectator . inject ( MatSnackBar ) . openFromComponent ) . toHaveBeenLastCalledWith (
106
+ expect ( matSnackBar . openFromComponent ) . toHaveBeenLastCalledWith (
106
107
NotificationComponent ,
107
108
expect . objectContaining ( {
108
109
horizontalPosition : 'left' ,
@@ -111,5 +112,10 @@ describe('NotificationService', () => {
111
112
data : expect . objectContaining ( { message : 'failure' , mode : NotificationMode . Failure } )
112
113
} )
113
114
) ;
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 ( ) ;
114
120
} ) ;
115
121
} ) ;
0 commit comments