Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions tests/unit/hooks/usePendingConciergeResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,27 @@ describe('usePendingConciergeResponse', () => {
});

it('should cancel the timer on unmount and not apply the action', async () => {
// Given a pending concierge response
// Given a pending concierge response with a short delay
const timerDelay = SHORT_DELAY;
await Onyx.merge(`${ONYXKEYS.COLLECTION.PENDING_CONCIERGE_RESPONSE}${REPORT_ID}`, {
reportAction: fakeConciergeAction,
displayAfter: Date.now() + SHORT_DELAY,
displayAfter: Date.now() + timerDelay,
});
await waitForBatchedUpdates();

// Switch to fake timers so we can advance past the deadline deterministically
jest.useFakeTimers();

const {unmount} = renderHook(() => usePendingConciergeResponse(REPORT_ID));
await waitForBatchedUpdates();

// When the hook unmounts before the delay
unmount();

// And we wait past the delay
await delay(SHORT_DELAY + 50);
// Advance well past the timer deadline — if clearTimeout were missing, the callback would fire here
jest.advanceTimersByTime(timerDelay + 1000);

// Restore real timers before async assertions
jest.useRealTimers();
await waitForBatchedUpdates();

// Then the action should NOT be in REPORT_ACTIONS (timer was cleaned up)
Expand Down
Loading