front/__tests__/Search.test.tsx
2024-10-19 08:16:51 +03:00

24 lines
753 B
TypeScript

import React from 'react';
import { render, screen, fireEvent } from '@testing-library/react';
import Search from '../src/components/home/Search.jsx';
describe('Search Component', () => {
it('should render the Search button', () => {
render(<Search search={() => {}} item="testItem" />);
const searchButton = screen.getByText(/find/i);
expect(searchButton).toBeInTheDocument();
});
it('should call the search function with the correct item when clicked', () => {
const mockSearch = jest.fn();
const item = 'testItem';
render(<Search search={mockSearch} item={item} />);
const searchButton = screen.getByText(/find/i);
fireEvent.click(searchButton);
expect(mockSearch).toHaveBeenCalledWith(item);
});
});