test: optimize InputPrompt tests with fake timers

This commit is contained in:
mkorwel
2026-04-21 17:25:40 +00:00
parent 559983098e
commit 13d4a6e332
@@ -250,6 +250,7 @@ describe('InputPrompt', () => {
};
beforeEach(() => {
vi.useFakeTimers();
vi.resetAllMocks();
coreEvents.removeAllListeners();
vi.spyOn(
@@ -1588,7 +1589,9 @@ describe('InputPrompt', () => {
});
// We need to wait a bit to ensure handleAutocomplete was NOT called
await new Promise((resolve) => setTimeout(resolve, 100));
await act(async () => {
await vi.advanceTimersByTimeAsync(100);
});
expect(mockCommandCompletion.handleAutocomplete).not.toHaveBeenCalled();
unmount();
@@ -2691,7 +2694,6 @@ describe('InputPrompt', () => {
describe('paste auto-submission protection', () => {
beforeEach(() => {
vi.useFakeTimers();
mockedUseKittyKeyboardProtocol.mockReturnValue({
enabled: false,
checking: false,
@@ -2699,7 +2701,6 @@ describe('InputPrompt', () => {
});
afterEach(() => {
vi.useRealTimers();
vi.restoreAllMocks();
});
@@ -2873,9 +2874,6 @@ describe('InputPrompt', () => {
});
describe('enhanced input UX - keyboard shortcuts', () => {
beforeEach(() => vi.useFakeTimers());
afterEach(() => vi.useRealTimers());
it('should clear buffer on Ctrl-C', async () => {
const onEscapePromptChange = vi.fn();
props.onEscapePromptChange = onEscapePromptChange;
@@ -3242,7 +3240,9 @@ describe('InputPrompt', () => {
stdin.write('\x1b[Z'); // Shift+Tab
});
await new Promise((resolve) => setTimeout(resolve, 100));
await act(async () => {
await vi.advanceTimersByTimeAsync(100);
});
expect(mockHandleAutocomplete).not.toHaveBeenCalled();
unmount();
@@ -3651,7 +3651,9 @@ describe('InputPrompt', () => {
stdin.write('\x1b[Z'); // Shift+Tab
});
await new Promise((resolve) => setTimeout(resolve, 100));
await act(async () => {
await vi.advanceTimersByTimeAsync(100);
});
expect(mockAccept).not.toHaveBeenCalled();
unmount();