1+ import { waitFor } from '@testing-library/react' ;
2+ 13import {
24 mockAccountNotifications ,
35 mockSingleAccountNotifications ,
@@ -15,7 +17,7 @@ describe('renderer/utils/notifications/native.ts', () => {
1517 } ) ;
1618
1719 describe ( 'triggerNativeNotifications' , ( ) => {
18- it ( 'should raise a native notification and play sound for a single new notification' , ( ) => {
20+ it ( 'should raise a native notification and play sound for a single new notification' , async ( ) => {
1921 const settings : SettingsState = {
2022 ...defaultSettings ,
2123 playSound : true ,
@@ -26,8 +28,11 @@ describe('renderer/utils/notifications/native.ts', () => {
2628 auth : mockAuth ,
2729 settings,
2830 } ) ;
31+ // wait for async native handling (generateGitHubWebUrl) to complete
32+ await waitFor ( ( ) =>
33+ expect ( window . gitify . raiseNativeNotification ) . toHaveBeenCalledTimes ( 1 ) ,
34+ ) ;
2935
30- expect ( window . gitify . raiseNativeNotification ) . toHaveBeenCalledTimes ( 1 ) ;
3136 expect ( window . gitify . raiseNativeNotification ) . toHaveBeenCalledWith (
3237 expect . stringContaining (
3338 mockSingleAccountNotifications [ 0 ] . notifications [ 0 ] . repository
@@ -36,14 +41,19 @@ describe('renderer/utils/notifications/native.ts', () => {
3641 expect . stringContaining (
3742 mockSingleAccountNotifications [ 0 ] . notifications [ 0 ] . subject . title ,
3843 ) ,
39- null ,
44+ expect . stringContaining (
45+ mockSingleAccountNotifications [ 0 ] . notifications [ 0 ] . repository
46+ . html_url ,
47+ ) ,
4048 ) ;
4149
42- expect ( raiseSoundNotificationMock ) . toHaveBeenCalledTimes ( 1 ) ;
50+ await waitFor ( ( ) =>
51+ expect ( raiseSoundNotificationMock ) . toHaveBeenCalledTimes ( 1 ) ,
52+ ) ;
4353 expect ( raiseSoundNotificationMock ) . toHaveBeenCalledWith ( 0.2 ) ;
4454 } ) ;
4555
46- it ( 'should raise a native notification and play sound for multiple new notifications' , ( ) => {
56+ it ( 'should raise a native notification and play sound for multiple new notifications' , async ( ) => {
4757 const settings : SettingsState = {
4858 ...defaultSettings ,
4959 playSound : true ,
@@ -54,15 +64,19 @@ describe('renderer/utils/notifications/native.ts', () => {
5464 auth : mockAuth ,
5565 settings,
5666 } ) ;
67+ await waitFor ( ( ) =>
68+ expect ( window . gitify . raiseNativeNotification ) . toHaveBeenCalledTimes ( 1 ) ,
69+ ) ;
5770
58- expect ( window . gitify . raiseNativeNotification ) . toHaveBeenCalledTimes ( 1 ) ;
5971 expect ( window . gitify . raiseNativeNotification ) . toHaveBeenCalledWith (
6072 'Gitify' ,
6173 'You have 4 notifications' ,
6274 null ,
6375 ) ;
6476
65- expect ( raiseSoundNotificationMock ) . toHaveBeenCalledTimes ( 1 ) ;
77+ await waitFor ( ( ) =>
78+ expect ( raiseSoundNotificationMock ) . toHaveBeenCalledTimes ( 1 ) ,
79+ ) ;
6680 expect ( raiseSoundNotificationMock ) . toHaveBeenCalledWith ( 0.2 ) ;
6781 } ) ;
6882
0 commit comments