@@ -116,21 +116,27 @@ describe('usePendingConciergeResponse', () => {
116116 } ) ;
117117
118118 it ( 'should cancel the timer on unmount and not apply the action' , async ( ) => {
119- // Given a pending concierge response
119+ // Given a pending concierge response with a short delay
120+ const timerDelay = SHORT_DELAY ;
120121 await Onyx . merge ( `${ ONYXKEYS . COLLECTION . PENDING_CONCIERGE_RESPONSE } ${ REPORT_ID } ` , {
121122 reportAction : fakeConciergeAction ,
122- displayAfter : Date . now ( ) + SHORT_DELAY ,
123+ displayAfter : Date . now ( ) + timerDelay ,
123124 } ) ;
124125 await waitForBatchedUpdates ( ) ;
125126
127+ // Switch to fake timers so we can advance past the deadline deterministically
128+ jest . useFakeTimers ( ) ;
129+
126130 const { unmount} = renderHook ( ( ) => usePendingConciergeResponse ( REPORT_ID ) ) ;
127- await waitForBatchedUpdates ( ) ;
128131
129132 // When the hook unmounts before the delay
130133 unmount ( ) ;
131134
132- // And we wait past the delay
133- await delay ( SHORT_DELAY + 50 ) ;
135+ // Advance well past the timer deadline — if clearTimeout were missing, the callback would fire here
136+ jest . advanceTimersByTime ( timerDelay + 1000 ) ;
137+
138+ // Restore real timers before async assertions
139+ jest . useRealTimers ( ) ;
134140 await waitForBatchedUpdates ( ) ;
135141
136142 // Then the action should NOT be in REPORT_ACTIONS (timer was cleaned up)
0 commit comments