From 22a2739b91d57d6d4c07fa570699fc08eb39431e Mon Sep 17 00:00:00 2001 From: jedarden Date: Fri, 22 May 2026 16:08:31 -0400 Subject: [PATCH] fix(tests): fix CommandPalette test mock instance capture Fixed test setup to correctly capture the mock instances that were actually used during CommandPalette construction. The previous approach of re-calling blessedMock.box() after clearing mocks resulted in checking different mock instances than those used by the actual palette object. Changed from: - Calling blessedMock.box() after construction (different instances) To: - Accessing blessedMock.box.mock.results[0]?.value (same instances) This ensures tests correctly verify the behavior of the actual CommandPalette instance, not mock instances that were never used by the palette. Co-Authored-By: Claude Opus 4.7 --- src/tui/components/CommandPalette.test.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/tui/components/CommandPalette.test.ts b/src/tui/components/CommandPalette.test.ts index c861e54..0524490 100644 --- a/src/tui/components/CommandPalette.test.ts +++ b/src/tui/components/CommandPalette.test.ts @@ -71,24 +71,18 @@ describe('CommandPalette', () => { mockScreen = createMockScreen(); onSubmit = vi.fn() as (command: string) => void; - // Get mock instances - const blessedMock = blessed as any; - mockBox = blessedMock.box(); - mockInput = blessedMock.textbox(); - mockList = blessedMock.list(); - - // Reset mock instances - vi.clearAllMocks(); - + // Clear mocks but DO NOT clear them after construction + // We need to capture the SAME instances that the palette uses palette = new CommandPalette({ parent: mockScreen, onSubmit, }); - // Re-capture after construction - mockBox = blessedMock.box(); - mockInput = blessedMock.textbox(); - mockList = blessedMock.list(); + // Capture the instances that were ACTUALLY USED during construction + const blessedMock = blessed as any; + mockBox = blessedMock.box.mock.results[0]?.value; + mockInput = blessedMock.textbox.mock.results[0]?.value; + mockList = blessedMock.list.mock.results[0]?.value; }); describe('Fuzzy Search', () => {