fix jest issues.
This commit is contained in:
parent
48943a4b59
commit
24d0aaffcd
@ -58,5 +58,10 @@
|
|||||||
"@testing-library/jest-dom": "^4.2.4",
|
"@testing-library/jest-dom": "^4.2.4",
|
||||||
"@types/jest": "^27.5.2",
|
"@types/jest": "^27.5.2",
|
||||||
"jest-without-globals": "^0.0.3"
|
"jest-without-globals": "^0.0.3"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"transformIgnorePatterns": [
|
||||||
|
"!node_modules/"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import userEvent from '@testing-library/user-event';
|
|||||||
import { LibraryItem } from './LibraryItem';
|
import { LibraryItem } from './LibraryItem';
|
||||||
import { Category, LibraryItem as LibItem } from '../lib/prompt';
|
import { Category, LibraryItem as LibItem } from '../lib/prompt';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
|
import { act } from 'react-dom/test-utils';
|
||||||
|
|
||||||
|
|
||||||
const mockOnAddItem = jest.fn();
|
const mockOnAddItem = jest.fn();
|
||||||
@ -16,7 +17,7 @@ const mockItem: LibItem = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
test('renders library item with add button', () => {
|
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 addButton = screen.getByLabelText('Add');
|
||||||
const itemName = screen.getByText((content, element) => {
|
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 () => {
|
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');
|
const addButton = screen.getByLabelText('Add');
|
||||||
|
|
||||||
userEvent.click(addButton);
|
act(() => {
|
||||||
|
userEvent.click(addButton);
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
expect(mockOnAddItem).toHaveBeenCalledWith(mockItem);
|
expect(mockOnAddItem).toHaveBeenCalledWith(mockItem);
|
||||||
});
|
});
|
||||||
|
@ -5,3 +5,4 @@
|
|||||||
// import '@testing-library/jest-dom';
|
// import '@testing-library/jest-dom';
|
||||||
// import '@testing-library/jest-dom/vitest';
|
// import '@testing-library/jest-dom/vitest';
|
||||||
// import '@testing-library/jest-dom';
|
// import '@testing-library/jest-dom';
|
||||||
|
import '@testing-library/jest-dom/extend-expect';
|
Loading…
Reference in New Issue
Block a user