@@ -81,4 +81,38 @@ describe("useAppVisibilityWatchdog", () => {
8181
8282 expect ( captureException ) . not . toHaveBeenCalled ( ) ;
8383 } ) ;
84+
85+ it ( "does not report after unmounting before the deadline" , ( ) => {
86+ const ref = { current : mountElement ( "0" , 1200 , 800 ) } ;
87+ const { unmount } = renderHook ( ( ) => useAppVisibilityWatchdog ( ref , true ) ) ;
88+
89+ unmount ( ) ;
90+ vi . advanceTimersByTime ( 3000 ) ;
91+
92+ expect ( captureException ) . not . toHaveBeenCalled ( ) ;
93+ } ) ;
94+
95+ it ( "arms when active flips from false to true" , ( ) => {
96+ const ref = { current : mountElement ( "0" , 1200 , 800 ) } ;
97+ const { rerender } = renderHook (
98+ ( { active } ) => useAppVisibilityWatchdog ( ref , active ) ,
99+ { initialProps : { active : false } } ,
100+ ) ;
101+
102+ vi . advanceTimersByTime ( 3000 ) ;
103+ expect ( captureException ) . not . toHaveBeenCalled ( ) ;
104+
105+ rerender ( { active : true } ) ;
106+ vi . advanceTimersByTime ( 3000 ) ;
107+ expect ( captureException ) . toHaveBeenCalledOnce ( ) ;
108+ } ) ;
109+
110+ it ( "does nothing when the ref never attaches" , ( ) => {
111+ const ref = { current : null } ;
112+ renderHook ( ( ) => useAppVisibilityWatchdog ( ref , true ) ) ;
113+
114+ vi . advanceTimersByTime ( 3000 ) ;
115+
116+ expect ( captureException ) . not . toHaveBeenCalled ( ) ;
117+ } ) ;
84118} ) ;
0 commit comments