Skip to content

Commit

Permalink
feat: ✨ enhance Button component with onClick handler
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdyer committed Jan 22, 2025
1 parent 645738b commit df2d944
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
13 changes: 12 additions & 1 deletion src/components/Button/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@ import { render, screen } from '@testing-library/react';
import Button from './Button';

describe('Button', () => {
test('renders button component', () => {
test('should render button component', () => {
render(<Button />);

const buttonElement = screen.getByText(/Button/i);

expect(buttonElement).toBeInTheDocument();
});

test('should call onClick when button is clicked', () => {
const onClick = jest.fn();

render(<Button onClick={onClick} />);

const buttonElement = screen.getByText(/Button/i);
buttonElement.click();

expect(onClick).toHaveBeenCalled();
});
});
14 changes: 9 additions & 5 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React from 'react';
export interface ButtonProps {
onClick?: () => void;
}

export interface ButtonProps {}

const Button: React.FC<ButtonProps> = () => {
return <button type="button">Button</button>;
const Button = ({ onClick }: ButtonProps) => {
return (
<button type="button" onClick={onClick}>
Button
</button>
);
};

export default Button;

0 comments on commit df2d944

Please sign in to comment.