From b83a31e8c9a1425572eca7959148ff10117f708a Mon Sep 17 00:00:00 2001 From: mkorwel Date: Fri, 17 Apr 2026 19:51:03 +0000 Subject: [PATCH] test: fix useShellHistory tests --- .../cli/src/ui/hooks/useShellHistory.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/cli/src/ui/hooks/useShellHistory.test.ts b/packages/cli/src/ui/hooks/useShellHistory.test.ts index 2ed8608141..2eaf25186e 100644 --- a/packages/cli/src/ui/hooks/useShellHistory.test.ts +++ b/packages/cli/src/ui/hooks/useShellHistory.test.ts @@ -109,6 +109,7 @@ describe('useShellHistory', () => { MOCKED_HISTORY_FILE, 'utf-8', ); + expect(result.current.history).toEqual(['cmd2', 'cmd1']); }); let command: string | null = null; @@ -154,6 +155,12 @@ describe('useShellHistory', () => { expect(mockedFs.readFile).toHaveBeenCalled(); }); + vi.useFakeTimers(); + // Wait for state updates to flush + await act(async () => { + await vi.advanceTimersByTimeAsync(10); + }); + act(() => { result.current.addCommandToHistory('new_command'); }); @@ -186,6 +193,7 @@ describe('useShellHistory', () => { // Wait for history to be loaded: ['cmd3', 'cmd2', 'cmd1'] await waitFor(() => { expect(mockedFs.readFile).toHaveBeenCalled(); + expect(result.current.history).toEqual(['cmd3', 'cmd2', 'cmd1']); }); let command: string | null = null; @@ -259,6 +267,12 @@ describe('useShellHistory', () => { expect(mockedFs.readFile).toHaveBeenCalled(); }); + vi.useFakeTimers(); + // Wait for state updates to flush + await act(async () => { + await vi.advanceTimersByTimeAsync(10); + }); + act(() => { result.current.addCommandToHistory('new_cmd'); }); @@ -293,6 +307,12 @@ describe('useShellHistory', () => { expect(mockedFs.readFile).toHaveBeenCalled(); }); + vi.useFakeTimers(); + // Wait for state updates to flush + await act(async () => { + await vi.advanceTimersByTimeAsync(10); + }); + act(() => { result.current.addCommandToHistory('cmd1'); });