diff --git a/src/app/components/__tests__/FireCalculatorForm.test.tsx b/src/app/components/__tests__/FireCalculatorForm.test.tsx index 14addae..428c8bb 100644 --- a/src/app/components/__tests__/FireCalculatorForm.test.tsx +++ b/src/app/components/__tests__/FireCalculatorForm.test.tsx @@ -70,15 +70,16 @@ describe('FireCalculatorForm', () => { }); }); - it('allows changing inputs', () => { - // using fireEvent for reliability with number inputs in jsdom + it('allows changing inputs', async () => { render(); const savingsInput = screen.getByRole('spinbutton', { name: /Monthly Savings/i }); fireEvent.change(savingsInput, { target: { value: '2000' } }); - expect(savingsInput).toHaveValue(2000); + await waitFor(() => { + expect(savingsInput).toHaveValue(2000); + }); }); it('validates inputs', async () => { diff --git a/vitest.setup.ts b/vitest.setup.ts index bff97bb..ab8856e 100644 --- a/vitest.setup.ts +++ b/vitest.setup.ts @@ -1,2 +1,20 @@ -import "@testing-library/jest-dom"; +import '@testing-library/jest-dom'; +import { vi } from 'vitest'; +// Provide a basic matchMedia mock for jsdom so components using media queries +// (e.g. pointer detection in Tooltip) do not throw during tests. +if (!window.matchMedia) { + Object.defineProperty(window, 'matchMedia', { + writable: true, + value: vi.fn().mockImplementation((query: string) => ({ + matches: false, + media: query, + onchange: null, + addListener: vi.fn(), // deprecated but still used in some libs + removeListener: vi.fn(), + addEventListener: vi.fn(), + removeEventListener: vi.fn(), + dispatchEvent: vi.fn(), + })), + }); +}