diff --git a/package.json b/package.json index bf53939..eee1d9a 100644 --- a/package.json +++ b/package.json @@ -58,5 +58,10 @@ "@testing-library/jest-dom": "^4.2.4", "@types/jest": "^27.5.2", "jest-without-globals": "^0.0.3" + }, + "jest": { + "transformIgnorePatterns": [ + "!node_modules/" + ] } } diff --git a/src/components/LibraryItem.test.tsx b/src/components/LibraryItem.test.tsx index 1733fbc..0a80348 100644 --- a/src/components/LibraryItem.test.tsx +++ b/src/components/LibraryItem.test.tsx @@ -4,6 +4,7 @@ import userEvent from '@testing-library/user-event'; import { LibraryItem } from './LibraryItem'; import { Category, LibraryItem as LibItem } from '../lib/prompt'; import { randomUUID } from 'crypto'; +import { act } from 'react-dom/test-utils'; const mockOnAddItem = jest.fn(); @@ -16,7 +17,7 @@ const mockItem: LibItem = { }; test('renders library item with add button', () => { - render(); + render(); const addButton = screen.getByLabelText('Add'); const itemName = screen.getByText((content, element) => { @@ -30,11 +31,14 @@ test('renders library item with add button', () => { }); test('calls onAddItem when add button is clicked', async () => { - render(); + render(); const addButton = screen.getByLabelText('Add'); - userEvent.click(addButton); + act(() => { + userEvent.click(addButton); + }) + expect(mockOnAddItem).toHaveBeenCalledWith(mockItem); }); diff --git a/src/setupTests.ts b/src/setupTests.ts index 04cce62..1c44141 100644 --- a/src/setupTests.ts +++ b/src/setupTests.ts @@ -4,4 +4,5 @@ // learn more: https://github.com/testing-library/jest-dom // import '@testing-library/jest-dom'; // import '@testing-library/jest-dom/vitest'; -// import '@testing-library/jest-dom'; \ No newline at end of file +// import '@testing-library/jest-dom'; +import '@testing-library/jest-dom/extend-expect'; \ No newline at end of file