Skip to content

Commit

Permalink
test: added test cases for toggle button component
Browse files Browse the repository at this point in the history
  • Loading branch information
niloofar-deriv committed Jun 18, 2024
1 parent 03e9006 commit d56a055
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { ToggleButton } from '../ToggleButton';

const mockOnClick = jest.fn();

describe('ToggleButton component', () => {
it('renders correctly', () => {
render(<ToggleButton onClick={mockOnClick} />);
expect(screen.getByRole('button')).toBeInTheDocument();
expect(screen.getByRole('img')).toBeInTheDocument();
});

it('calls onClick when clicked', async () => {
render(<ToggleButton onClick={mockOnClick} />);
await userEvent.click(screen.getByRole('button'));
expect(mockOnClick).toHaveBeenCalledTimes(1);
});
});

0 comments on commit d56a055

Please sign in to comment.