import { render, fireEvent } from '@testing-library/react';
import { Button } from './Button';
import { describe, vi, it, expect } from 'vitest';
describe('Button', () => {
it('renders without crashing', () => {
const container = render(
);
expect(container).toMatchSnapshot();
});
it('renders a button element with given children as a Span', () => {
const { getByRole } = render(
);
const button = getByRole('button');
expect(button).toBeInTheDocument();
expect(button.tagName).toBe('BUTTON');
expect(button).toHaveTextContent('Click me!');
});
it('renders a button element with given children if children is not a React element', () => {
const label = 'Click me!';
const { getByDisplayValue } = render(
);
const input = getByDisplayValue(label);
expect(input).toBeInTheDocument();
expect(input.tagName).toBe('INPUT');
expect(input).toHaveAttribute('value', label);
});
it('appelle onClick quand le bouton est cliqué', () => {
const handleClick = vi.fn();
const { getByText } = render(
);
const buttonElement = getByText('Cliquez ici');
fireEvent.click(buttonElement);
expect(handleClick).toHaveBeenCalledTimes(1);
});
it('renders an input element with given label without a child', () => {
const label = 'Click me!';
const { getByDisplayValue } = render(