fix(tests): fix CommandPalette test mock instance capture
Some checks are pending
CI / test (18.x) (push) Waiting to run
CI / test (20.x) (push) Waiting to run
CI / test (22.x) (push) Waiting to run

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 <noreply@anthropic.com>
This commit is contained in:
jedarden 2026-05-22 16:08:31 -04:00
parent 838fe5c654
commit 22a2739b91

View file

@ -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', () => {