@@ -37,6 +37,7 @@ describe('ChannelService', () => {
3737 userID : string ;
3838 pinMessage : jasmine . Spy ;
3939 unpinMessage : jasmine . Spy ;
40+ activeChannels : { [ key : string ] : Channel < DefaultStreamChatGenerics > } ;
4041 } ;
4142 let events$ : Subject < ClientEvent > ;
4243 let connectionState$ : Subject < 'online' | 'offline' > ;
@@ -63,6 +64,7 @@ describe('ChannelService', () => {
6364 userID : user . id ,
6465 pinMessage : jasmine . createSpy ( ) ,
6566 unpinMessage : jasmine . createSpy ( ) ,
67+ activeChannels : { } ,
6668 } ;
6769 events$ = new Subject ( ) ;
6870 TestBed . configureTestingModule ( {
@@ -586,6 +588,8 @@ describe('ChannelService', () => {
586588 service . activeChannel$ . pipe ( first ( ) ) . subscribe ( ( c ) => ( channel = c ! ) ) ;
587589 const spy = jasmine . createSpy ( ) ;
588590 service . channels$ . subscribe ( spy ) ;
591+ mockChatClient . activeChannels [ channel . cid ] = channel ;
592+ spyOn ( channel , 'stopWatching' ) ;
589593 ( channel as MockChannel ) . handleEvent ( 'channel.hidden' , {
590594 type : 'channel.hidden' ,
591595 channel,
@@ -594,6 +598,7 @@ describe('ChannelService', () => {
594598 let channels = spy . calls . mostRecent ( ) . args [ 0 ] as Channel [ ] ;
595599
596600 expect ( channels . find ( ( c ) => c . cid === channel . cid ) ) . toBeUndefined ( ) ;
601+ expect ( channel . stopWatching ) . toHaveBeenCalledWith ( ) ;
597602
598603 ( channel as MockChannel ) . handleEvent ( 'channel.hidden' , {
599604 type : 'channel.visible' ,
@@ -650,6 +655,8 @@ describe('ChannelService', () => {
650655 service . activeChannel$ . pipe ( first ( ) ) . subscribe ( ( c ) => ( channel = c ! ) ) ;
651656 const spy = jasmine . createSpy ( ) ;
652657 service . channels$ . subscribe ( spy ) ;
658+ mockChatClient . activeChannels [ channel . cid ] = channel ;
659+ spyOn ( channel , 'stopWatching' ) ;
653660 ( channel as MockChannel ) . handleEvent ( 'channel.deleted' , {
654661 type : 'channel.deleted' ,
655662 channel,
@@ -658,6 +665,7 @@ describe('ChannelService', () => {
658665 const channels = spy . calls . mostRecent ( ) . args [ 0 ] as Channel [ ] ;
659666
660667 expect ( channels . find ( ( c ) => c . cid === channel . cid ) ) . toBeUndefined ( ) ;
668+ expect ( channel . stopWatching ) . toHaveBeenCalledWith ( ) ;
661669 } ) ;
662670
663671 it ( 'should call #customChannelDeletedHandler, if channel is deleted and handler is provided' , async ( ) => {
@@ -894,6 +902,8 @@ describe('ChannelService', () => {
894902 . subscribe ( ( channels ) => ( channel = channels ! [ 1 ] ) ) ;
895903 const spy = jasmine . createSpy ( ) ;
896904 service . channels$ . subscribe ( spy ) ;
905+ mockChatClient . activeChannels [ channel . cid ] = channel ;
906+ spyOn ( channel , 'stopWatching' ) ;
897907 spyOn ( service , 'setAsActiveChannel' ) ;
898908 events$ . next ( {
899909 eventType : 'notification.removed_from_channel' ,
@@ -904,6 +914,7 @@ describe('ChannelService', () => {
904914
905915 expect ( channels . find ( ( c ) => c . cid === channel . cid ) ) . toBeUndefined ( ) ;
906916 expect ( service . setAsActiveChannel ) . not . toHaveBeenCalled ( ) ;
917+ expect ( channel . stopWatching ) . toHaveBeenCalledWith ( ) ;
907918 } ) ;
908919
909920 it ( 'should remove channel form the list if user is removed from channel, and emit new active channel' , async ( ) => {
0 commit comments