mirror of
https://github.com/Nezumi-2711/react-training.git
synced 2026-09-22 13:38:51 +00:00
Improve test case function
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { RenderResult, fireEvent, render } from '@testing-library/react';
|
||||
|
||||
// Components
|
||||
import OrderBy from '.';
|
||||
|
||||
jest.mock('react-router-dom');
|
||||
|
||||
describe('Order', () => {
|
||||
const options = [
|
||||
{
|
||||
value: 'value1',
|
||||
label: 'Option 1',
|
||||
},
|
||||
{
|
||||
value: 'value2',
|
||||
label: 'Option 2',
|
||||
},
|
||||
];
|
||||
|
||||
let wrapper: RenderResult | null = null;
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = render(<OrderBy options={options} />);
|
||||
});
|
||||
|
||||
test('Should render correctly', () => {
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('handleClick should work correctly', async () => {
|
||||
const mockSearchParams = jest.fn();
|
||||
// useSearchParams.search = mockSearchParams;
|
||||
// setSearchParams = jest.fn();
|
||||
|
||||
const nameButton = wrapper!.getByText('Name');
|
||||
fireEvent.click(nameButton);
|
||||
|
||||
expect(mockSearchParams).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user