fix jest issues.

This commit is contained in:
Jordan 2024-02-26 09:05:43 -08:00
parent 48943a4b59
commit 24d0aaffcd
3 changed files with 14 additions and 4 deletions

View File

@ -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/"
]
}
}

View File

@ -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(<LibraryItem item={mockItem} onAddItem={mockOnAddItem} />);
render(<LibraryItem item={mockItem} onInsertItem={mockOnAddItem} />);
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(<LibraryItem item={mockItem} onAddItem={mockOnAddItem} />);
render(<LibraryItem item={mockItem} onInsertItem={mockOnAddItem} />);
const addButton = screen.getByLabelText('Add');
userEvent.click(addButton);
act(() => {
userEvent.click(addButton);
})
expect(mockOnAddItem).toHaveBeenCalledWith(mockItem);
});

View File

@ -5,3 +5,4 @@
// import '@testing-library/jest-dom';
// import '@testing-library/jest-dom/vitest';
// import '@testing-library/jest-dom';
import '@testing-library/jest-dom/extend-expect';