more unit tests

This commit is contained in:
2025-11-25 19:06:23 -08:00
parent 4997aa922a
commit fd39c4309c
3 changed files with 17 additions and 4 deletions

View File

@@ -6,6 +6,15 @@ import { MemoryRouter } from 'react-router-dom';
import App from './App';
import * as apiClient from './services/apiClient';
// Mock pdfjs-dist to prevent the "DOMMatrix is not defined" error in JSDOM.
// The library expects browser APIs that don't exist in the test environment.
// We provide a more complete mock that includes stubs for the functions it uses.
vi.mock('pdfjs-dist', () => ({
GlobalWorkerOptions: { workerSrc: '' },
getDocument: vi.fn(() => ({
promise: Promise.resolve({ getPage: vi.fn() }),
})),
}));
// Mock child components to isolate the App component
vi.mock('./features/flyer/FlyerDisplay', () => ({ FlyerDisplay: () => <div data-testid="flyer-display-mock">Flyer Display</div> }));
vi.mock('./features/flyer/ExtractedDataTable', () => ({ ExtractedDataTable: () => <div data-testid="extracted-data-table-mock">Extracted Data Table</div> }));

View File

@@ -21,6 +21,8 @@ vi.mock('../../services/logger', () => ({
const mockUser: User = { user_id: 'user-123', email: 'test@example.com' };
let generateSpeechSpy: Mock;
const mockLists: ShoppingList[] = [
{
shopping_list_id: 1,
@@ -62,8 +64,6 @@ describe('ShoppingListComponent (in shopping feature)', () => {
onRemoveItem: mockOnRemoveItem,
};
let generateSpeechSpy: Mock;
beforeEach(() => {
vi.clearAllMocks();
// Mock browser APIs

View File

@@ -12,8 +12,12 @@ vi.mock('./App', () => ({
// Mock pdfjs-dist to prevent the "DOMMatrix is not defined" error in JSDOM.
// This is necessary because index.tsx imports App.tsx, which imports pdfjs-dist.
vi.mock('pdfjs-dist', () => ({
GlobalWorkerOptions: { workerSrc: '' },
vi.mock('pdfjs-dist', async (importOriginal) => {
const actual = await importOriginal<typeof import('pdfjs-dist')>();
return {
...actual,
getDocument: vi.fn().mockReturnValue({ promise: Promise.resolve({ getPage: vi.fn() }) }),
};
}));
describe('index.tsx', () => {