@@ -500,11 +500,11 @@ describe('ChannelPreview', () => {
500500 } ,
501501 render ,
502502 ) ;
503- expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
503+ await expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
504504 await act ( ( ) => {
505505 dispatchNotificationMarkRead ( { client } ) ;
506506 } ) ;
507- expectUnreadCountToBe ( screen . getByTestId , 0 ) ;
507+ await expectUnreadCountToBe ( screen . getByTestId , 0 ) ;
508508 } ) ;
509509
510510 it ( 'should set unread count to 0 for current channel' , async ( ) => {
@@ -518,11 +518,11 @@ describe('ChannelPreview', () => {
518518 } ,
519519 render ,
520520 ) ;
521- expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
521+ await expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
522522 await act ( ( ) => {
523523 dispatchNotificationMarkRead ( { channel : channelInPreview , client } ) ;
524524 } ) ;
525- expectUnreadCountToBe ( screen . getByTestId , 0 ) ;
525+ await expectUnreadCountToBe ( screen . getByTestId , 0 ) ;
526526 } ) ;
527527
528528 it ( 'should be ignored if not targeted for the current channel' , async ( ) => {
@@ -537,11 +537,11 @@ describe('ChannelPreview', () => {
537537 } ,
538538 render ,
539539 ) ;
540- expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
540+ await expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
541541 await act ( ( ) => {
542542 dispatchNotificationMarkRead ( { channel : activeChannel , client } ) ;
543543 } ) ;
544- expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
544+ await expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
545545 } ) ;
546546 } ) ;
547547
@@ -558,7 +558,7 @@ describe('ChannelPreview', () => {
558558 } ,
559559 render ,
560560 ) ;
561- expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
561+ await expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
562562 await act ( ( ) => {
563563 dispatchNotificationMarkUnread ( {
564564 channel : channelInPreview ,
@@ -567,7 +567,7 @@ describe('ChannelPreview', () => {
567567 user : otherUser ,
568568 } ) ;
569569 } ) ;
570- expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
570+ await expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
571571 } ) ;
572572
573573 it ( 'should be ignored if not targeted for the current channel' , async ( ) => {
@@ -582,7 +582,7 @@ describe('ChannelPreview', () => {
582582 } ,
583583 render ,
584584 ) ;
585- expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
585+ await expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
586586 await act ( ( ) => {
587587 dispatchNotificationMarkUnread ( {
588588 channel : activeChannel ,
@@ -591,23 +591,26 @@ describe('ChannelPreview', () => {
591591 user,
592592 } ) ;
593593 } ) ;
594- expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
594+ await expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
595595 } ) ;
596596
597597 it ( "should set unread count from client's unread count state for active channel" , async ( ) => {
598598 const unreadCount = 0 ;
599+ const nextUnreadCount = 5 ;
599600 const activeChannel = c1 ;
600- activeChannel . countUnread = ( ) => unreadCount ;
601+ jest
602+ . spyOn ( activeChannel , 'countUnread' )
603+ . mockReturnValueOnce ( unreadCount )
604+ . mockReturnValueOnce ( nextUnreadCount ) ;
601605 renderComponent (
602606 {
603607 activeChannel,
604608 channel : activeChannel ,
605609 } ,
606610 render ,
607611 ) ;
608- expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
612+ await expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
609613
610- const eventPayload = { unread_channels : 2 , unread_messages : 5 } ;
611614 await act ( ( ) => {
612615 dispatchNotificationMarkUnread ( {
613616 channel : activeChannel ,
@@ -616,24 +619,27 @@ describe('ChannelPreview', () => {
616619 user,
617620 } ) ;
618621 } ) ;
619- expectUnreadCountToBe ( screen . getByTestId , eventPayload . unread_messages ) ;
622+ await expectUnreadCountToBe ( screen . getByTestId , nextUnreadCount ) ;
620623 } ) ;
621624
622625 it ( "should set unread count from client's unread count state for non-active channel" , async ( ) => {
623626 const unreadCount = 0 ;
627+ const nextUnreadCount = 5 ;
624628 const channelInPreview = c0 ;
625629 const activeChannel = c1 ;
626- channelInPreview . countUnread = ( ) => unreadCount ;
630+ jest
631+ . spyOn ( channelInPreview , 'countUnread' )
632+ . mockReturnValueOnce ( unreadCount )
633+ . mockReturnValueOnce ( nextUnreadCount ) ;
627634 renderComponent (
628635 {
629636 activeChannel,
630637 channel : channelInPreview ,
631638 } ,
632639 render ,
633640 ) ;
634- expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
641+ await expectUnreadCountToBe ( screen . getByTestId , unreadCount ) ;
635642
636- const eventPayload = { unread_channels : 2 , unread_messages : 5 } ;
637643 await act ( ( ) => {
638644 dispatchNotificationMarkUnread ( {
639645 channel : channelInPreview ,
@@ -642,7 +648,7 @@ describe('ChannelPreview', () => {
642648 user,
643649 } ) ;
644650 } ) ;
645- expectUnreadCountToBe ( screen . getByTestId , eventPayload . unread_messages ) ;
651+ await expectUnreadCountToBe ( screen . getByTestId , nextUnreadCount ) ;
646652 } ) ;
647653 } ) ;
648654
0 commit comments